我有一个问题,我想用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"}
]
答案 0 :(得分:0)
[
{
"cityName": "New York",
"peoples": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones"
}
]
},
{
"cityName": "San Francisco",
"peoples": [
{
"firstName": "Fred",
"lastName": "Boening"
}
]
}
]