This is a very basic question. I just want to display a test batch of JSON with PHP, but I think I don't have the correct formatting, since the data received looks garbled when outputed, and it causes a data error if I try to decode it.
I know the JSON data is gzipped, but even with decompressing, I get an error. Here is the code I've tried:
<?php
// create a new cURL resource
$ch = curl_init("http://api.stackoverflow.com/1.0/questions?pagesize=5");
// set options
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL
$json = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
// Decode JSON
var_dump(json_decode( gzuncompress($json) ));
?>
The output is:
Warning: gzuncompress() [function.gzuncompress]:
data error [on this line ==> "var_dump(json_decode( gzuncompress($json) ));"]
NULL
(stuff in the square brackets is my translation of its, "error on line ...")
What am I doing wrong?
Thanks!