我正在试验JSON格式,并不确定如何使用它来构建族树。这是我得到的(保持简单,只列出父亲,他的孩子以及这些孩子是否有孩子,我没有列出配偶的姓名)。虽然它的效果很好,但我不知道这样做的最佳方法(即我的方法干干净净,例如可伸缩)。如何创建JSON格式的家族树结构
6
A
回答
4
最简单的办法:
{
"Jonathan Smith": {
"Adam": {
"Suzy": {},
"Clare": {},
"Aaron": {},
"Simon": {}
},
"Timmy": {},
"Alison": {
"Natasha": {}, "Zak": {}
}
}
}
更强大的结构:
{
"Smiths": {
"Jonathan Smith": { "id": 0},
"Adam Smith": { "id": 1, "father": 0 },
"Suzy Smith": { "id": 4, "father": 1 },
"Clare Smith": { "id": 5, "father": 1 },
"Aaron Smith": { "id": 6, "father": 1 },
"Simon Smith": { "id": 7, "father": 1 },
"Timmy Smith": { "id": 2, "father": 0 },
"Alison Smith": { "id":3, "father": 0 },
"Natasha Smith": { "id": 8, "father": 3 },
"Zak Smith": { "id": 9, "father": 3 }
}
}
添加更多的关系,母亲,丈夫和妻子。
{
"Smiths": {
"Jonathan Smith": { "id": 0, "wife": [10]},
"Suzan Smith": { "id": 10, "born": "Suzan Jones", "husband": [0] },
"Adam Smith": { "id": 1, "father": 0, "mother": 10 },
"Suzy Smith": { "id": 4, "father": 1 },
"Clare Smith": { "id": 5, "father": 1 },
"Aaron Smith": { "id": 6, "father": 1 },
"Simon Smith": { "id": 7, "father": 1 },
"Timmy Smith": { "id": 2, "father": 0, "mother": 10 },
"Alison Smith": { "id":3, "father": 0, "mother": 10 },
"Natasha Smith": { "id": 8, "father": 3 },
"Zak Smith": { "id": 9, "father": 3 }
}
}
有时它是非常容易使用Javascript
var familyTree = {}
familyTree["Dick Jones"] = { id: 1234, father: 213 }
使用JSON工作这将允许您添加,删除,使用的功能,能够检查错误,然后就拿到产生JSON致电:
JSON.stringify(familyTree)
0
你必须注意,因为你添加的覆盖格式json数据。尝试使用允许您以简单的方式响应您想要执行的查询的结构。
0
试试这个:
{'name': 'John'}, {'name': 'Jack', 'child_of': 'John'}, {'name': 'Charlie', 'child_of': 'Jack', 'grand_child_of': 'John'}
0
树木的工作是很困难的JSON,但也许你可以使用等级的概念(代在这个例子中),这样你可以了解叔伯,堂兄弟等
[
{
"id":100,
"name":"Jhon Smith",
"generation":1,
"children":[
{
"id":101,
"name":"Michael Smith",
"generation":2,
"children":null
},
{
"id":102,
"name":"Diana Smith",
"children":[
{
"id":301,
"name":"Britney Smith",
"generation":3,
"children":null
}
]
}
]
},
{
"id":200,
"name":"Richard Smith",
"generation":1,
"children":[
{
"id":101,
"name":"Michael Smith",
"generation":2,
"children":null
},
{
"id":102,
"name":"Diana Smith",
"generation":2,
"children":null
}
]
}
]
相关问题
- 1. 创建家族树的树
- 2. 如何格式排列家族树
- 3. C++中的家族树结构
- 4. 递归Java数据结构 - 创建一个家族树的数组
- 5. 如何用Perl构建一个家族树?
- 6. 如何为树结构创建JSON模式?
- 7. 构建JSON树结构
- 8. 创建JSON树结构,儿童
- 9. GSON - 从Java创建JSON树结构
- 10. 树结构的JSON模式
- 11. 如何获取JSON格式的石墨树结构
- 12. PHP MYSQL家族树“约”页
- 13. 家族树项目javafx
- 14. 如何创建树状结构
- 15. 如何在Python中创建树结构?
- 16. 如何在Java中创建树结构?
- 17. 如何创建B +树数据结构
- 18. 创建家谱结构
- 19. 从文本文件创建二进制(家族)树
- 20. Neo4j结果(以JSON格式)创建D3树图
- 21. JSON文件创建和添加节点JSON树型结构
- 22. 如何为Go创建JSON结构
- 23. 如何在java中创建json结构?
- 24. 具有多个伙伴和兄弟姐妹的家族树的数据结构?
- 25. swi-prolog家族树中的错误
- 26. c中的微软家族树#
- 27. 家族树上的SQL循环
- 28. 删除家族树中的节点
- 29. extjs树模式的JSON结构
- 30. 如何创建JSON格式的Java
您识别人通过他们的名字。名称不是唯一的,因此这是一个糟糕的结构。 ID更适合于需要唯一性的情况。 – ComFreek
这个数据是_users_ type还是创建的东西? – Bulkan
@Bulkan号这是我正在创建的数据。 – Andy