代码之家  ›  专栏  ›  技术社区  ›  Cody Raspien

解析json-获取空输出-php

  •  0
  • Cody Raspien  · 技术社区  · 7 年前

    我的代码:

    $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 回复  |  直到 7 年前
        1
  •  3
  •   Rayne    7 年前

    你必须把里面的第一个元素 ['results'] .

    echo $json_response['results'][0]['tags'][0]['tag'];