我有一个如下的json,
{
"responseHeader":{
"status":0,
"QTime":1
},
"spellcheck":{
"suggestions":[
"goo",
{
"numFound":5,
"startOffset":0,
"endOffset":3,
"suggestion":[
"good",
"googl",
"goodby",
"goos",
"goodwil"
]
},
"collation",
"good"
]
}
}
我尝试了下面的 php 代码来获取建议中的元素列表,即 good,google,goodby,goos,goodwill
$myArray = json_decode($response, true);
foreach ($myArray['spellcheck']['suggestion'] as $doc) {
echo $doc;
}
但是得到这个错误
Notice: Undefined index: suggestion in /Applications/XAMPP/xamppfiles/htdocs/ir/suggestions.php on line 9
如何获得建议的各个元素?