我已经多次解析 JSON 数据,但由于某种原因无法找到嵌套数据时使用的正确语法。我正在尝试从此 JSON 解析“资产”,但无论我尝试什么,都会继续获得提供的无效参数 foreach()。
"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"
}
],
我希望它会类似于...
$json = json_decode($jsondata, true);
foreach ($json as $item)
{
foreach ($item['assets']->RAM as $asset)
{
echo $asset->model;
}