我如何从以下JSON中选择每个标题的数据?我有JSON解码,但我不知道如何选择我想要的部分.
{
"responseData": {
"results": [
{
"title": "Justin Giesbrecht 749",
"titleNoFormatting": "Justin Giesbrecht 749",
},
{
"title": "Gopher dunes 09",
"titleNoFormatting": "Gopher dunes 09",
},
{
"title": "dirtbike Justin",
"titleNoFormatting": "dirtbike Justin",
},
{
"title": "A Warming",
"titleNoFormatting": "A Warming",
}
],
"cursor": {
"pages": [
{
"start": "0",
"label": 1
},
{
"start": "4",
"label": 2
}
],
"estimatedResultCount": "6",
"currentPageIndex": 0,
}
},
"responseDetails": null,
"responseStatus": 200
}
Run Code Online (Sandbox Code Playgroud)
我以为会是这样的,但我什么都没得到:
echo "Response ". $jsonS->responseData->results[1]->title;
Run Code Online (Sandbox Code Playgroud)
实际上你已经正确阅读了标题部分,这是JSON无效的.
将JSON复制到JSON验证器/ lint(例如http://www.jsonlint.com/)将显示您在几个地方的最后一个对象属性之后有其他(逗号)(确切地说,在每个'titleFormatting'属性之后5个位置)之后'currentPageIndex').
如果你修复这些错误并使用json_decode例如解析它:
$jsonS = json_decode($json_text);
Run Code Online (Sandbox Code Playgroud)
然后你自己的代码:
echo "Response " . $jsonS->responseData->results[1]->title;
Run Code Online (Sandbox Code Playgroud)
将输出第二个(索引1是第二个索引)结果标题
响应Gopher dunes 09
| 归档时间: |
|
| 查看次数: |
5698 次 |
| 最近记录: |