JSON 不能显示为 PHP 数组


json can't be displayed as php array

我检查的示例看起来很简单,但我无法弄清楚我做错了什么。我正在尝试在 PHP 中将 JSON 文本转换并显示为对象数组。

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

它不输出任何东西。 但是当我打印$json时,输出很好

好吧,这不是json,请尝试

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

请注意字符串用 " 括起来,另请参阅 http://json.org