我有这个
JSON文件:
http://www.jeewanaryal.com/angryQuiz/eighties/json/eighties.json
我正在尝试在PHP中解码它,如下所示:
$json = file_get_contents('http://www.jeewanaryal.com/angryQuiz/eighties/json/eighties.json'); $data = json_decode($json); var_dump($data);
但是,我得到的输出是NULL.我错过了什么吗?
使用
PHP.NET json_last_error()的例子我发现你的json语法是不正确的:
switch (json_last_error()) { case JSON_ERROR_NONE: echo ' - No errors'; break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; break; case JSON_ERROR_Syntax: echo ' - Syntax error,malformed JSON'; break; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters,possibly incorrectly encoded'; break; default: echo ' - Unknown error'; break; }
输出:
- Syntax error,malformed JSON
但是,我在以下网站检查了你的json代码,但它说有效:
> http://www.freeformatter.com/json-validator.html
> http://jsonlint.com/
> http://json.parser.online.fr/
> http://jsonformatter.curiousconcept.com/