当前位置:Gxlcms > PHP教程 > 这样的JSON应该如何写

这样的JSON应该如何写

时间:2021-07-01 10:21:17 帮助过:9人阅读

这样的JSON应该 怎么写?
数据库数据如下:
我想写成这样的JSON:
[
{
"id": "4",
"name": "天天有鱼",
"sort": "2",
"dishes": [
{
"id": "5",
"Name": "清蒸桂鱼",
"Price": "100",
"Discount": "124",
"ParentID_id": "4",
"Image": "abc.jpg",
"Unit": "例",
"Sale": "80",
"Stock": 999
},
{
"id": "6",
"Name": "酸汤桂鱼",
"Price": "50",
"Discount": "57",
"ParentID_id": "4",
"Image": "a12.jpg",
"Unit": "例",
"Sale": "50",
"Stock": 999
}
]
},
{
"id": "7",
"name": "天天有鱼",
"sort": "1",
"dishes": [
{
"id": "8",
"Name": "生拌凉菜",
"Price": "60",
"Discount": "80",
"ParentID_id": "7",
"Image": "dg.jpg",
"Unit": "例",
"Sale": "30",
"Stock": 999
}
]
}
]
应该 如何写?
------解决思路----------------------
一般要用递归
无论是递归还是不递归,精华区都有相关的帖子。自己去看一下

人气教程排行