首頁  >  文章  >  後端開發  >  这样的JSON应该 如何写

这样的JSON应该 如何写

WBOY
WBOY原創
2016-06-13 12:19:191126瀏覽

这样的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
            }
        ]
    }
]
应该 如何写?
------解决思路----------------------
一般要用递归
无论是递归还是不递归,精华区都有相关的帖子。自己去看一下

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn