python递归解析嵌套json
json数据⽰例
google chrome怎么用{"node":"a","subNodes":[{"node":"a1","subNodes":[{"node":"a11","subNodes":[{"node":"a111","subNodes":[]},{"node":"a112","subNodes":[]}]},{"node":"a12"," subNodes":[]}]},{"node":"a2","subNodes":[]}]}
pilipili里站怎么进{"node":"b","subNodes":[{"node":"b1","subNodes":[{"node":"b11","subNodes":[{"node":"b111","subNodes":[]}]}]}]}
将json样式数据存⼊a.txt⽂件中
递归解析json数据
# -*- coding:utf-8 -*-
import json
# 递归打印解析节点及路径
def recursion(node_dict, node):
if len(node_dict) == 0:
tmp.append(node)svg推文
else:
python请求并解析json数据for i in node_dict:
('subNodes'), node+'-->'+i.get('node'))
f = open('a.txt')
for line in f:
data = json.loads(line)
node = ('node')
tmp = []
反编译工具有哪些
('subNodes'), node)
for i in tmp:
print(node, ':', i)
# ⼀⾏输出
# print(';'.join(tmp))
f.close()
输出结果:
a : a-->a1-->a11-->a111
a : a-->a1-->a11-->a112
a : a-->a1-->a12imgur1org
a : a-->a2
b : b-->b1-->b11-->b111
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论