【发布时间】:2020-12-06 23:22:09
【问题描述】:
如果嵌套最多 10 个级别,每个级别具有不同的长度,则存在父级、子级、孙子级和更多关系,如下面给出的 json (id 在每个列表中是唯一的)。找到uni_code 以将另一个对象(子对象)插入其列表的最佳方法是什么?
{
"id": "1",
"status": "active",
"created": "",
"children": [{
"id": "1",
"status": "active",
"created": "",
"children": [{
"id": "1",
"status": "active",
"created": "",
"children": [{
"id": "1",
"status": "active",
"created": "",
"children": [
],
"uni_code": "EGCFJ1"
},
{
"id": "1",
"status": "active",
"created": "",
"children": [
],
"uni_code": "D356RY"
},
],
"uni_code": "EGCFJ1"
},
],
"uni_code": "Y7TUP8"
},
{
"id": "4",
"status": "active",
"created": "",
"children": [
],
"uni_code": "WA1JNS"
},
],
"uni_code": "I429TD"
}
【问题讨论】:
-
你已经尝试了什么,你的想法是什么?
-
一个选项是循环遍历每个级别的所有元素。
-
@martineau 的解决方案工作
标签: python json for-loop recursion arraylist