原代码:
<?php
$html=file_get_contents("http://pad.skyozora.com/data/pets.json");
var_dump(json_decode($html,true)); //return null
var_dump(json_last_error()); // return 4
?>
输出:
NULL int(4)
改进后:
<?php
$html=file_get_contents("http://pad.skyozora.com/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