I've look high and low for a solution for this, but haven't found anything that is exactly what I am running into. I am using php to parse a JSON response that is nested in a way that makes it difficult to extract specific fields.
Here is a bit of the JSON:
{
"collection":{
"items":[
{
"href":"https://api.teamsnap.com/v3/members/MEMBERID",
"data":[
"name":"id",
"value": 0000000 // MEMBERID
},
{
"name":"type",
"value":"member"
},
{
"name":"address_city",
"value":""
},
{
"name":"address_state",
"value":""
},
Here is my php:
$json = file_get_contents($url, false, $context);
$result = json_decode($json);
foreach ($result->collection->items as $items=>$val) {
foreach ($val->data as $data=>$datasets) {
foreach ($datasets as $dataset=>$val) {
echo $dataset.': '.$val;
echo "<br>";
}
}
};
and this is a bit of the current output:
name: id
value: MEMBERID
name: first_name
value: MEMBERNAME
name: last_name
value: MEMBERNAME
what I want to do is be able to list all of the members in this response with their first and last name. I have tried using $val->first_name, $val['first_name']; and such but all result in a foreach error.
{) before your firstdatamember.