关系数据的JSON格式的最新状态?

时间:2014-10-08 08:47:34

标签: json

我有一个问题,我想用JSON显示一个SQL Like Database。我有以下概念:

一个城镇有不同的人住在那里。在SQL中,您将创建2个表。镇和人民。然后,人们将有一个TownID来获取其城镇的参考。

现在用JSON显示它的更好方法是什么:

方式1,在一个结构中

[
{"New York":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"}, 
    {"firstName":"Peter", "lastName":"Jones"}
]},
{"San Francisco":[
    {"firstName":"Fred", "lastName":"Boening"}
]}
]

方式2,SQL喜欢

[
    {"City":"New York", "id":"0"}, 
    {"City":"San Francisco", "id":"1"}
]
[
    {"CityId": "0", "firstName":"John", "lastName":"Doe"}, 
    {"CityId": "0", "firstName":"Anna", "lastName":"Smith"}, 
    {"CityId": "0", "firstName":"Peter", "lastName":"Jones"}
    {"CityId": "1", "firstName":"Fred", "lastName":"Boening"}
]

1 个答案:

答案 0 :(得分:0)

你的json看起来像这样的东西

[
    {
        "cityName": "New York",
        "peoples": [
            {
                "firstName": "John",
                "lastName": "Doe"
            },
            {
                "firstName": "Anna",
                "lastName": "Smith"
            },
            {
                "firstName": "Peter",
                "lastName": "Jones"
            }
        ]
    },
    {
        "cityName": "San Francisco",
        "peoples": [
            {
                "firstName": "Fred",
                "lastName": "Boening"
            }
        ]
    }
]