1

I am finding it hard to debug why json_decode is returning null.

Here is a var dump of the JSON I am trying to decode:

string(82) " {"total_goals":83,"total_games":30,"average_goals":"2.77"} " 

Which is valid JSON according to JSONLint.

var_dump($homeJSON);  // Returns above 
$json = json_decode($homeJSON); // Decode the json
var_dump($json); // Returns NULL

$homeJSON is reading file_get_contents(url) if that makes a difference.

JSON is coming from a file on another site:

$post_data = json_encode(array('total_goals' => $totalgoals, 'total_games' =>     $totalgames, 'average_goals' => $average_goals));

echo $post_data;

I have checked the BOM and removed it, and I am still getting NULL

CMS
  • 285
  • 1
  • 4
  • 10

0 Answers0