我已经设法将 notORM 对象转换为数组,但现在我想将数组转换为嵌套的 json 字符串。
$categoriesTable = $db->categories();
$resultant = array();
foreach($categoriesTable as $key => $object) {
foreach($object as $property => $value) {
$resultant[$property] = array_push($resultant, $value);
}
}
上面代码的输出是
{"code":"1013","message":"Contacts Sync Successful","data":{"0":"1","ID":33,"1":"Food","Title":34,"2":null,"Description":35,"3":null,"ImageURL":36,"4":"2","5":"Film","6":null,"7":null,"8":"3","9":"Outing","10":null,"11":null,"12":"4","13":"Shopping","14":null,"15":null,"16":"5","17":"Party","18":null,"19":null,"20":"6","21":"Sports","22":null,"23":null,"24":"7","25":"Travel","26":null,"27":null,"28":"8","29":"Others","30":null,"31":null}}
作为参考,我的类别表结构是:ID、标题、描述、ImageURL
但我希望 json 输出为
{"data":[{"table1":[{"ID":"1", "Title":"Abc"....}, {...}]}]}
等等请帮忙。那么它的php代码是什么?