我收到了这个错误:
尝试从Reddit's front page 打印密钥时解析错误:语法错误,C:\ wamp \ www \ test.php中的意外T_STRING 在第2行
如何解决* $ json_string *解析错误并显示Reddit's front page的密钥?提前谢谢。
test.php的
<?php
$json_string = "{"kind": "Listing", "data": {"modhash": "", "children": [{"kind": "t3", "data": {"domain": "i.imgur.com", "banned_by": null, "media_embed": {}, "subreddit": "pics", "selftext_html": null, "selftext": "", "likes": null, "link_flair_text": null, "id": "1d7lch", "clicked": false, "title": "Graves of a Catholic woman and her Protestant husband, who were not allowed to be buried together.", ... ";
$a = json_decode($json_string);
echo $a.keys();
?>
答案 0 :(得分:3)
将其包裹在单引号内或转义双引号?
答案 1 :(得分:2)
使用'来打开和关闭$ json_string的标签,如下所示:
$json_string='{"king": "Listing", ...}';
OR转义字符串里面的字符:
$json_string="{\"king\": \"Listing\", ...}";
答案 2 :(得分:2)
不要自己把它放在一个字符串中,只需使用它。
$a = json_decode(file_get_contents('http://www.reddit.com/.json'));
这会照顾你逃跑。