0

The examples I checked seems simple but I can't figure it out what I'm doing wrong. I'm trying to convert and display JSON text as object array in PHP.

$json = '{"color1":red, "color2":blue, "color3":yellow}';
    $arr= json_decode($json, true);
    print_r($arr);

It doesn't output anything. but when I print $json, the output is just fine

1 Answer 1

4

Well that's not json, try

$json = '{"color1":"red", "color2":"blue", "color3":"yellow"}';
$arr= json_decode($json, true);
print_r($arr);

notice the strings are quoted with ", also see http://json.org

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

1 Comment

oops, right that's why I was feeling iffy with my json.. I copied the json from a website. thanks

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.