我有一个 JSON 文件:
{
"first":{"a":[{"b":[{"c":"AAA"}]}],"d":111},
"second":{"a":[{"b":[{"c":"BBB"},{"c":"CCC"}]}],"d":222}
}
我需要用平面文本结构保存它,如下所示:
111
AAA
222
BBB
CCC
如何遍历 JSON?我所能做的就是:
import json
file_json = open('1.txt', mode='r', encoding='utf-8')
data = json.load(file_json)
file_json.close()
file_new = open('data.txt', mode='w', encoding='utf-8')
for number in data:
file_new.write(number + "\n")
file_new.close()
我明白了
first
second
但是我如何获得其余的数据?
我试过for number, data_rest in data:
了,但它得到了ValueError: too many values to unpack (expected 2)
。