I have a json file that i need to parse to php and display only some values that i need
<?php
// Read JSON file
$readjson = file_get_contents('output.json') ;
//Decode JSON
$data = json_decode($readjson, true);
//Print data
echo "<br/><br/> Employee names are: <br/>";
//Parse the employee name
foreach ($data as $emp) {
echo $emp['category.name']."<br/>";
}
?>
The output.json file contains some values ex:
{
"bizCode":10000,
"message":"0#0",
"data":[
{
"id":"sr:tournament:27070",
"events":[
{
"homeTeamName":"Independiente Santa Fe",
"awayTeamName":"America de Cali",
"sport":{
"name":"Football",
"category":{
"name":"Colombia",
"tournament":{
"name":"Primera A, Apertura"
}
}
},
},
{
"homeTeamName":"AD Cali",
"awayTeamName":"Millonarios FC",
"sport":{
"name":"Football",
"category":{
"name":"Colombia",
"tournament":{
"name":"Primera A, Apertura"
}
}
},
}
],
"categoryName":"Colombia",
}
]
}
I have test it but it's not showing any data and i can't find the issue. Maybe the problem is that i cant locate the exact path of the data?
Print:
"; //Parse the employee name foreach ($events as $emp) { echo $emp['category']['name']."
"; }` – user2178344 Dec 24 '20 at 10:36