JSON_ERROR_CTRL_CHAR 在使用 json_decode 时,none 的经典解决方案有效
JSON_ERROR_CTRL_CHAR while using json_decode, none of the classic solutions work
我一整天都在尝试解决这个问题,但无法让它发挥作用。本来应该很简单的事情。
问题是,我对此 URL 发出 GET 请求:http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b
然后,我尝试使用 PHP 函数 json_decode 将结果转换为 JSON 格式。我是这样做的:
$httpResponse = drupal_http_request('http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b');
$data = $httpResponse->data;
$datas = json_decode($data);
var_export($datas);
$error = json_last_error_msg();
echo "Error = $error";
和错误信息returns"Control character error, possibly incorrectly encoded"
我已经尝试过使用 stripslashes,删除 BOM,html_entities,删除一些初始字符,其中 none 个有效。
您必须将 "Accept-Encoding" header 设置为 "gzip, deflate",否则响应将被截断。
$httpResponse = drupal_http_request('http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b', array('Accept-Encoding' => 'gzip, deflater'));
$data = gzdecode($httpResponse->data);
我一整天都在尝试解决这个问题,但无法让它发挥作用。本来应该很简单的事情。
问题是,我对此 URL 发出 GET 请求:http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b
然后,我尝试使用 PHP 函数 json_decode 将结果转换为 JSON 格式。我是这样做的:
$httpResponse = drupal_http_request('http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b');
$data = $httpResponse->data;
$datas = json_decode($data);
var_export($datas);
$error = json_last_error_msg();
echo "Error = $error";
和错误信息returns"Control character error, possibly incorrectly encoded"
我已经尝试过使用 stripslashes,删除 BOM,html_entities,删除一些初始字符,其中 none 个有效。
您必须将 "Accept-Encoding" header 设置为 "gzip, deflate",否则响应将被截断。
$httpResponse = drupal_http_request('http://api.champion.gg/stats?api_key=851a15d4f271849f3beee664ea03db3b', array('Accept-Encoding' => 'gzip, deflater'));
$data = gzdecode($httpResponse->data);