参见英文答案 > Failed to json_decode string from file_get_contents 2个
我的代码:
<?PHP
header('Content-Type: application/json; charset=utf-8');
$url = "http://80.211.192.133:8117/stats";
$json = file_get_contents($url);
$obj = json_decode($json);
$error = json_last_error();
var_dump($error);
?>
我收到错误:
code 5 - Malformed UTF-8 characters when encoding callback response
有人可以帮助我吗?
解决方法:
问题来自服务器压缩数据. gzinflate会帮助你:
<?PHP
header('Content-Type: application/json; charset=utf-8');
$url = "http://80.211.192.133:8117/stats";
$data = file_get_contents($url);
$data = gzinflate( $data );
$obj = json_decode($data,true);
平心而论,@ Octopus也发现了重要的部分.