代码日常练习
2019-10-28 本文已影响0人
__XY__
遍历一个json的所有的value值
def run(a_json):
ret = []
if isinstance(a_json, dict):
for k, v in a_json.items():
ret += run(v)
elif isinstance(a_json, list):
for i in a_json:
ret += run(i)
else:
return [a_json]
return ret
a = {"a": {'b': {'c': 1, 'd': 2}}}
b = [{'a': 1, 'b': [{'d': 3, 'e': 4}]}]
a_ret = run(b)
print(a_ret)