Quick simple question: I am trying to extract an object from a JSON file in php. This is my code but I can’t seem to get it working:
<?php
$api2 = $json_decode(file_get_contents("https://api.riverside.rocks/v1/status"));
echo $api2[1];
?>
Please always remember that if you are trying to get the first object in the PHP, computers always count from 0, so you want the 0th object, like this:
$text = $api2[0]->text;
If I am correct you can also do something like this
echo $api2['objectname'];
I tried those but I had no luck
.
It might have something to do with the JSON decode. When I ran echo $api2;
it returned nothing.