I have parsed JSON data numerous times but for some reason cannot find the correct syntax to use when the data is nested. I am trying to parse the "assets" from this JSON but continue to get a invalid argument supplied foreach() regardless of what I try.
"3435":{
"name":"COLO-1014-SJ1",
"nickname":"US-SJC-004",
"type":"Colocated Server",
"location":"San Jose:55 S Market",
"assets":{
"CPU":[
{
"model":"Intel E3 1270"
}
],
"Hard Drives":[
{
"model":"Western Digital 500GB RE4 ABYX SATA"
},
{
"model":"Western Digital 500GB RE4 ABYX SATA"
},
{
"model":"Kingston 240GB SSD"
}
],
"RAM":[
{
"model":"Super Talent 4GB DDR3 1333 ECC"
},
{
"model":"Super Talent 4GB DDR3 1333 ECC"
},
{
"model":"Super Talent 4GB DDR3 1333 ECC"
},
{
"model":"Super Talent 4GB DDR3 1333 ECC"
}
],
I would expect it to be something along the lines of...
$json = json_decode($jsondata, true);
foreach ($json as $item)
{
foreach ($item['assets']->RAM as $asset)
{
echo $asset->model;
}