Hi I have a Json format like below:
{
"result":0,
"status":[
{
"id":"00001",
"vid":"yes"
},
{
"id":"00002",
"vid":"yes"
},
{
"id":"00003",
"vid":"no"
}
]
}
I want to use the json_decode
function in PHP to decode the id
values such as below:
00001
00002
00003
here is the code I am using:
$url = file_get_contents("URL");
foreach(json_decode($url, true) as $key=>$value){
foreach($value->status[0] as $key1=>$value1){
echo $value1->id;
}
}
The problem seems to be with status[0]
as far as I know using status[0]
is the only way to select the status
key. However I can't get the loop to work correctly.
I get the error: Trying to get property of non-object
meaning status[0]
is not finding status
in the Json array however I have no idea why this is since it works when I pull a value like:$id = $url->status[0]->id;
If anyone has any suggestions or advice I'd greatly appreciate it. Thanks