I am trying to parse and list a json file. I have it as Unicode-8 without BOM. File is operational. 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 doesn't this work?
<?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>";
}
?>
use $json = json_decode($jsondata);
instead of `$json = json_decode($jsondata,true); True parameter convert it into array not json object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With