Parse json with php 5 not working

I am trying to parse and list a json file. I have it as Unicode-8 without specification. The file is working. Structure:

// "games.json" : // {"data":[ // {"game":"5359","Date":"07/08/2015"}, // {"game":"5355","Date":"10/20/2007"}, .... <?php // copy file content into a string var $jsondata = file_get_contents("games.json"); // convert the string to a json object $json = json_decode($jsondata,true); var_dump($json); // DW! foreach($json["data"] as $data_X) {echo $data_X->game;} ?> 

Why is this not working?

+5
source share
2 answers
 <?php $jsonData = '{ "user":"John", "age":22, "country":"United States" }'; $phpArray = json_decode($jsonData); print_r($phpArray); foreach ($phpArray as $key => $value) { echo "<p>$key | $value</p>"; } 

? >

+2
source

use $json = json_decode($jsondata); instead of `$ json = json_decode ($ jsondata, true); A true parameter converts it to an array object, not json.

+1
source

All Articles