PHP无法解析此JSON字符串 - 出了什么问题?

时间:2011-02-25 10:58:28

标签: php json

<?php
$b = '{
    "encoding" : "UTF-8",    
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],
    "indent" : { "length" : 3, "use_space" = true }
}';

print "\n\n\n=================================\n";
$barr = json_decode($b, true);
print_r($barr);

?>

这不会在控制台上打印任何内容。上面的JSON格式有问题吗? - 或者我错过了一个技巧?

3 个答案:

答案 0 :(得分:4)

那是因为你的JSON无效。 Check out here.

此:

"use_space" = true 

必须:

"use_space" : true 

答案 1 :(得分:3)

indent属性的use_space属性中包含错误:

"indent" : { "length" : 3, "use_space" = true }

等于该应该是冒号。

"indent" : { "length" : 3, "use_space" : true }

答案 2 :(得分:1)

$b = '{
    "encoding" : "UTF-8",    
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],
    "indent" : { "length" : 3, "use_space" : true }
}';

print "\n\n\n=================================\n";
$barr = json_decode($b, true);
print_r($barr);

&GT;