This is the JSON output i want
{
"MainEvent":"Geelong v Essendon",
"OutcomeDateTime":"2014-06-27 19:51:00.0000000",
"Competitors":[
{
"Name":"Geelong",
"Win":"1.32"
},
{
"Name":"Essendon",
"Win":"3.40"
}
]
},
{
"MainEvent":"Hawthorn v Gold Coast",
"OutcomeDateTime":"2014-06-28 13:46:00.0000000",
"Competitors":[
{
"Name":"Geedlong",
"Win":"1.32d"
},
{
"Name":"Essenddon",
"Win":"3.40d"
}
]
}
This is my code
foreach ($SortedByDate as $key => $values){
foreach ($json_a as $root_element => $childnode) {
foreach( $childnode as $cKey => $subChild) {
$rootObj = array(
'MainEvent' => $subChild['MainEvent'],
'OutcomeDateTime' => $subChild['OutcomeDateTime'],
foreach($subChild['Competitors']['Competitors'] as $compKey => $compVal) {
$teamName = $compVal['Team'];
$win = $compVal['Win'];
$abc = array(
"Team" => $teamName,
"Win" => $win,
);
}
}
$rootObj ['Competitors'] = $abc;
}}
$abc="";
print json_encode($rootObj );
}
And i am getting this output . But comma is missing in my output. Can anyone give me some suggestions please?
{
"MainEvent":"Geelong v Essendon",
"OutcomeDateTime":"2014-06-27 19:51:00.0000000",
"Competitors":[
{
"Name":"Geelong",
"Win":"1.32"
},
{
"Name":"Essendon",
"Win":"3.40"
}
]
}
{
"MainEvent":"Hawthorn v Gold Coast",
"OutcomeDateTime":"2014-06-28 13:46:00.0000000",
"Competitors":[
{
"Name":"Geedlong",
"Win":"1.32d"
},
{
"Name":"Essenddon",
"Win":"3.40d"
}
]
}
I have tried these code but i am not sure how to add comma in my output JSON