Search code examples
phpjsonparsehub

How can i print json file that is produced from ParseHub on screen?


I use ParseHub to get data from an Ajax-based website. The data is returned in json file format. I have been struggling to print returned json file for hours, but could not be successful. Here is my php code:

<?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;


?>

By the way, json_decode() function didn't work. Can anyone help me?

UPDATE: I uploaded code and output of the code. You can check to give some ideas.

Code -> this link Output -> this link


Solution

  • From the ParseHub API documentation:

    The Content-Encoding of this response is always gzip.

    Try to use gzdecode function for your $result variable. And then decode it with json_decode().

    Note that it requires PHP 5 >= 5.4.0 or PHP 7 version. Also you can try to use Parsehub REST api wrapper class.