0

I have a JSON object, but I can't parse it in PHP.

$data = file_get_contents("http://noticiasjson.blob.core.windows.net/json3/super/map_minuto.json");
$json = json_decode($data, true);
var_dump($json);

The result is null.

What am I doing wrong?

SeGa
  • 9,454
  • 3
  • 31
  • 70
  • https://stackoverflow.com/questions/4343596/how-can-i-parse-a-json-file-with-php – Reda Meskali Jun 30 '18 at 17:52
  • 1
    I believe you may be facing a character encoding issue. If you `var_dump($data)` it's a string, but a string full of total gibberish. – Ryan Kozak Jun 30 '18 at 18:02
  • 1
    @RedaMeskali that link doesnt cover his actual issue. Which is, "unexpected character" (as reported by `echo json_last_error_msg();`). Its not valid JSON. – IncredibleHat Jun 30 '18 at 18:03
  • Are you sure you have [fopen wrappers](http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) enabled as per the notes section of [file_get_contents](http://php.net/manual/en/function.file-get-contents.php) – MC57 Jun 30 '18 at 18:05
  • I ran the json url though some online validators. The json fails. – Jason K Jun 30 '18 at 18:06
  • @JasonK Seemed ok to me when I validated it :s – MC57 Jun 30 '18 at 18:11
  • If you copy the file content and assign it as the value of `$data`, then all is fine (_"No error"_). But, if you fetch the content directly from the URI, then it looks weird (_"Control character error, possibly incorrectly encoded"_). So @RyanKozak is right: Your remote content is not properly encoded. – PajuranCodes Jun 30 '18 at 18:17
  • 1
    `Content-Encoding: gzip` is not supported by plain fopen http wrappers. – mario Jun 30 '18 at 18:20

0 Answers0