我如何在屏幕上打印从 ParseHub 生成的 json 文件?
How can i print json file that is produced from ParseHub on screen?
我使用 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() 函数不起作用。谁能帮帮我?
更新:我上传了代码和代码的输出。大家可以看看给点意见。
The Content-Encoding of this response is always gzip.
尝试为您的 $result 变量使用 gzdecode 函数。然后用 json_decode().
解码
请注意,它需要 PHP 5 >= 5.4.0 或 PHP 7 版本。
您也可以尝试使用 Parsehub REST api wrapper class.
我使用 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() 函数不起作用。谁能帮帮我?
更新:我上传了代码和代码的输出。大家可以看看给点意见。
The Content-Encoding of this response is always gzip.
尝试为您的 $result 变量使用 gzdecode 函数。然后用 json_decode().
解码请注意,它需要 PHP 5 >= 5.4.0 或 PHP 7 版本。 您也可以尝试使用 Parsehub REST api wrapper class.