I've a php object that I want to convert to the following json format.
All the data values are object via a php object in the format:
Array ( [0] => stdClass Object ( [id] => 2
[s1] => 1485
[name] => 1485
[credit] => ''
[caption] => ''
)
)
I'm trying to group the credit, caption, etc. under child. Also, I'm unable to get the [ after date in the json format.
{
"mydata":
{
"name":Name,
"type":"default",
"date": [
{
"s1":"1485",
"name":"1485",
"child":
{
"credit":"",
"caption":""
}
}]
}
}
Currently, my code looks like:
foreach ($hits as $hit) {
$data->mydata->date->s1 = $hit->s1;
$data->mydata->date->name = $hit->name;
$data->mydata->date->credit = $hit->credit;
$data->mydata->date->caption = $hit->caption;
}
$a = json_encode($data);
set
$date->mydata->dateto an array and you will get the[]And why not making more nested structures?