0

My code:

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

My JSON:

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

I am trying to output "herb". I have looked up through examples but cannot figure out where the bug is.

I am reading results and then the trees.

Cody Raspien
  • 1,753
  • 5
  • 26
  • 51

1 Answers1

3

You have to fetch the first element inside ['results'].

echo $json_response['results'][0]['tags'][0]['tag'];
Rayne
  • 2,620
  • 20
  • 28