Reputation: 143
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
Upvotes: 0
Views: 59
Reputation: 97717
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
Upvotes: 4