Sorry if this is rookie standard. The nesting really confuses me. Code here:
$json= '[{ "all":
"{"data":
[ {"name": "Kofi", "age":13}, {"name": "Jay", "age":17} ]
}"
}]' ;
$decode = json_decode($json);
$names= $decode->all->data->name;
// I want to retrieve "Kofi" and "Jay"
foreach ($names as $name){
echo $name;
}
I want to retrieve Kofi, Jay I get the error: Trying to get property 'all' of non-object
allwhose value is a string of JSON data. You need to decode the outer array, then decode the value of theallkey.$decode[0]->all->data[0]->name;and$decode[0]->all->data[1]->name;