开发者

PHP fails to parse this JSON string - what's wrong?

<?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);

?>

This prints nothing on the console. Is tehre something wrong with the JSON 开发者_JS百科format above? - or am I missing a trick?


That is because your JSON isn't valid. Check out here.

This:

"use_space" = true 

Must be:

"use_space" : true 


The indent property has an error in its use_space property:

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

The equal should be a colon.

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


$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);

?>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜