解析JSON-获取空输出-PHP

时间:2018-06-19 18:13:53

标签: php json parsing

我的代码:

$json_response = json_decode($response, true);
$tag= $json_response['results']['tags'][0]['tag'];
print $tag;

我的JSON:

{
  "results": [
    {
      "tagging_id": null,
      "image": "image.jpg",
      "tags": [
        {
          "confidence": 100,
          "tag": "herb"
        },
        {
          "confidence": 98.3637619018555,
          "tag": "plant"
        }
      ]
    }
  ]
}

我正在尝试输出“草药”。我通过示例进行了查找,但无法确定错误在哪里。

我先阅读结果,然后再阅读树。

1 个答案:

答案 0 :(得分:3)

您必须获取['results']中的第一个元素。

echo $json_response['results'][0]['tags'][0]['tag'];
相关问题