当前位置: 代码迷 >> PHP >> 这样的JSON应该 如何写
  详细解决方案

这样的JSON应该 如何写

热度:24   发布时间:2016-04-28 17:29:58.0
这样的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
            }
        ]
    }
]
应该 如何写?
------解决思路----------------------
一般要用递归
无论是递归还是不递归,精华区都有相关的帖子。自己去看一下
  相关解决方案