json_decode 解析返回值为空
$html=file_get_contents("http://xxxxx/data/pets.json"); var_dump(json_decode($html,true)); //return null var_dump(json_last_error()); // return 4
输出:
NULL int(4)
改进后: $html=file_get_contents("http://pxxxxx/data/pets.json"); $html=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $html); var_dump(json_decode($html, true)); var_dump(json_last_error());
其他方法:
https://stackoverflow.com/questions/29326045/php-json-decode-return-error-code-4
https://stackoverflow.com/questions/689185/json-decode-returns-null-after-webservice-call