I’m completely noob with json.
I need to parse a json that returns a result like this:
"response":{
"status":1,
"data":{
"16":{
"Offer":{
"id":"16",
"advertiser_id":null,
"name":"My Offer",
"description":null,
"require_approval":"0",
"require_terms_and_conditions":0,
"terms_and_conditions":null,
"offer_url":"http://",
"preview_url":"http://",
}
},
"17":{
"Offer":{
"id":"17",
"advertiser_id":null,
"name":"My Other Offer",
"description":null,
"require_approval":"0",
"require_terms_and_conditions":0,
"terms_and_conditions":null,
"offer_url":"http://",
"preview_url":"http://",
}
},
},
"errors":[]
}
I need to access all offers name, but I’m not able to access trying this :
$url = "jsonurl";
$string = file_get_contents($url);
$json_a=json_decode($string,true);
foreach ($json_a['data']['offer'] as $offer_a) {
echo $offer_a[name];
}
What I’m doing wrong ??
thank you all in advance.
You seem to be skipping the
16. But this is easily debugged by doing this.This will display the tree in an array/object. In this case an array.
But I guess this will work:
If you need all offer names: