这是我试图迭代的以下 JSON 结构
{
"AS":{
"Query":"vi",
"FullResults":1,
"Results":[
{
"Type":"AS",
"Suggests":[
{
"Txt":"videos",
"Type":"AS",
"Sk":""
},
{
"Txt":"vipjatt",
"Type":"AS",
"Sk":"AS1"
},
{
"Txt":"vit",
"Type":"AS",
"Sk":"AS2"
},
{
"Txt":"vijaya bank",
"Type":"AS",
"Sk":"AS3"
},
{
"Txt":"videocon d2h",
"Type":"AS",
"Sk":"AS4"
},
{
"Txt":"visarev",
"Type":"AS",
"Sk":"AS5"
},
{
"Txt":"vijaya karnataka",
"Type":"AS",
"Sk":"AS6"
},
{
"Txt":"video songs",
"Type":"AS",
"Sk":"AS7"
}
]
}
]
}
}
这是我用来迭代它并尝试访问“Txt”属性的代码
$data = $info->get($url);
$content = json_decode($data);
$i = 0;
foreach($content->AS->Results as $item) {
$each = $item->Suggests[$i]->Txt;
$i++;
echo $each;
}
但我只能访问“Txt”属性的第一次出现。我的代码有什么问题?为什么它打印“Txt”属性的每一个外观?