1

I just noticed an odd result with my code:

$data = @file_get_contents($url);  //gets json format from API
return $data;

It returns a random character in front of the first { and after the last }.
Because of this, I cant use json_decode() because the json is now invalid because of the extra characters.

I have checked the actual api url and it doesn't have those random characters.
Why could this be happening?

Note: Sometimes it even returns a black diamond with a white question mark.


I'm reading API's from Steam Community.


I improvised with a temporary fix while im trying to find the code causing the problem.

$data = substr($data, 1, -1);
madziikoy
  • 1,447
  • 7
  • 22
  • 32

1 Answers1

0

Seems like you have a character encoding issue.

The response header of the api-request:

Content-Type: application/json; charset=UTF-8 
Content-Encoding: gzip  

Please have a look at an equivalent issue here.

Community
  • 1
  • 1
NiMeDia
  • 995
  • 1
  • 15
  • 27