存储json文件,逐条按行存储
with open('xxx.json', 'a+', encoding='utf8')as f:
json.dump(temp, f, ensure_ascii=False)
f.write('\n')
读取json文件,逐条按行读取
with open('xxx.json', 'r', encoding='utf8') as f:
for temp in islice(f, 0, None):
temp = json.loads(temp)
print(temp['xxxx1'])
print(temp['xxxx2'])
本文详细介绍了如何使用Python的json模块逐条按行存储和读取JSON文件,包括正确的代码示例和注意事项,适合初学者和需要优化现有代码的开发者。
3045

被折叠的 条评论
为什么被折叠?



