我开发这样的php代码:
while($row = mysql_fetch_array ($result))
{
$catalogue = array(
'catalogue_id' => $row[0],
'catalogue_name' => $row[1],
'catalogue_cover' => $row[2],
'category' => array(
'id' => $row[3],
'name' => $row[4],
'cover' => $row[5],
'item' => array (
'id' => $row[6],
'name' => $row[7],
'cover' => $row[8],
'description' => $row[9],
'price' =>$row[10]
)
),
);
array_push($json, $catalogue);
}
$jsonresult = array2json($json);
echo $jsonresult;
结果json是:
[
{
"catalogue_id": "59",
"catalogue_name": "IT Catalog",
"catalogue_cover": "http://192.168.0.22:90/Ecatalogue/catalogue/covers/511b21f398969.jpeg",
"category": {
"id": "60",
"name": "Computer Accessory",
"cover": "http://192.168.0.22:90/Ecatalogue/category/covers/511b2e11e8b26.jpg",
"item": {
"id": "61",
"name": "CD",
"cover": "http://192.168.0.22:90/Ecatalogue/item/covers/511b2e1da3063.jpg",
"description": "",
"price": "0.00"
}
}
},
{
"catalogue_id": "59",
"catalogue_name": "IT Catalog",
"catalogue_cover": "http://192.168.0.22:90/Ecatalogue/catalogue/covers/511b21f398969.jpeg",
"category": {
"id": "61",
"name": "IT Category",
"cover": "http://192.168.0.22:90/Ecatalogue/category/covers/511caf7329f63.jpeg",
"item": {
"id": "63",
"name": "IT Item",
"cover": "http://192.168.0.22:90/Ecatalogue/item/covers/511cafa17cce5.jpeg",
"description": "",
"price": "0.00"
}
}
}
]
但我想像这样组合相同的目录:
[
{
"catalogue_id": "59",
"catalogue_name": "IT Catalog",
"catalogue_cover": "http://192.168.0.22:90/Ecatalogue/catalogue/covers/511b21f398969.jpeg",
"category": {
"id": "60",
"name": "Computer Accessory",
"cover": "http://192.168.0.22:90/Ecatalogue/category/covers/511b2e11e8b26.jpg",
"item": {
"id": "61",
"name": "CD",
"cover": "http://192.168.0.22:90/Ecatalogue/item/covers/511b2e1da3063.jpg",
"description": "",
"price": "0.00"
},
"category-2": {
"id": "61",
"name": "IT Category",
"cover": "http://192.168.0.22:90/Ecatalogue/category/covers/511caf7329f63.jpeg",
"item": {
"id": "63",
"name": "IT Item",
"cover": "http://192.168.0.22:90/Ecatalogue/item/covers/511cafa17cce5.jpeg",
"description": "",
"price": "0.00"
}
}
}
}
]
我怎样才能做到这一点 ?