7

I have a json as shown below.I want to access the value of adult.However when i do echo json_decode($json_response, true); i get Array to string conversion.What is wrong here ?

 {
      "responses": [
        {
          "safeSearchAnnotation": {
            "adult": "VERY_UNLIKELY",
            "spoof": "VERY_UNLIKELY",
            "medical": "UNLIKELY",
            "violence": "LIKELY"
          }
        }
      ]
    }

1 Answer 1

14

The function json_decode returns an array. You can't echo an array, or you'll get that conversion error.

You want to use print_r instead:

print_r(json_decode($json_response, true));

See here: https://3v4l.org/K3UfP

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.