I get this Error Notice: Trying to get property of non-object each time the array is at index 0.
But works if there are more than 1 value in the array.
$jsonurl = "https://example.org/json_response/";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json, true);
foreach ( $json_output as $output ) {
echo $output->id;
}
Using var_dump($json_output); does returns the data.
Edited
array (size=2)
'id' => string 'xYue78ee9es' (length=10)
'username' => string 'peesBEE' (length=7)
But throws Error when I try to accessing the variable like this echo $output->id;.
var_dump($output);to see the content of each iteration. Given the Notice message, the first one isn't even an objecttrueonjson_decode, you're already free of any objects inside your variable, so using the->arrow operator is unneededtrue, what comes out of it is an array, treat it as such. posting yourvar_dump($json_output)would help those who answered below