将字典写入json文件

data_dict = {'150245': {'name': '存在', 'class': '1', 'cvedate': '2013-01-17', 'type': '202', 'sid': '150245', 'action': '1'}, '150905': {'name': '本地文件', 'class': '1', 'cvedate': '', 'type': '901', 'sid': '150905', 'action': '1', }}

json_str = json.dumps(data_dict, ensure_ascii=False, indent=4)  // ensure_ascii=False(输出中文), indent=4(缩进为4)

with open('new_pvs_library4.json', 'w', encoding='utf-8') as f:
f.write(json_str)

猜你喜欢

转载自www.cnblogs.com/lihengman/p/10885468.html