Li = [1, 2,
[11, 22,
[111, 222, [1111, 2222,
{"x": "xxx",
"y": "yyy",
"z": [5566, 7788,
{"keyA": 888, "keyB": 999}]},
]]]]
def get_item(it, k):
if isinstance(it, dict):
for d in it:
if isinstance(it[d], (dict, list)):
get_item(it[d], k)
else:
if d == k:
print(d, it[d])
# else:
# print(it[d]) #取消注释,可以打印出全部
elif isinstance(it, list):
for l in it:
if isinstance(l, (dict, list)):
get_item(l, k)
# else:
# print(l) #取消注释,可以打印出全部
get_item(Li, "keyA")
json返回值中,不确定位置的值,可以用递归的方式找 字典对应KEY的值