参见英文答案 > 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也发现了重要的部分.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。