PHP JSON GET在网页上正确显示,但不在PHP

参见英文答案 > 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 

但是当你从$url变量打开链接时,它显示正确的数据.

有人可以帮助我吗?

解决方法:

问题来自服务器压缩数据. 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也发现了重要的部分.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...