我使用ParseHub从一个基于Ajax的网站获取数据。数据以json文件格式返回。几个小时以来,我一直在努力打印返回的json文件,但没有成功。以下是我的php代码:
<?php
header('Content-Type: application/json;charset=utf-8');
$params = http_build_query(array(
"api_key" => "xxxxx",
"format" => "json"
));
$result = file_get_contents(
'https://www.parsehub.com/api/v2/projects/{MY_RUN_TOKEN}/last_ready_run/data?'.$params,
false,
stream_context_create(array(
'http' => array(
'method' => 'GET'
)
))
);
echo $result;
?>顺便说一下,json_decode()函数没有工作。有谁可以帮我?
更新:我上传了代码和输出的代码。你可以检查一下,给出一些想法。
发布于 2017-10-26 23:20:58
此响应的内容编码始终是gzip。
尝试对您的gzdecode变量使用$result函数。然后用json_decode()对其进行解码。
请注意,它需要PHP5 >= 5.4.0或PHP7版本。此外,您还可以尝试使用Parsehub REST包装器类。
https://stackoverflow.com/questions/46963909
复制相似问题