一个json数据如何写入文件中保存
import json
data = {
'name': 'Larry',
'website': 'google.com',
'from': 'Michigan'
}
with open("data.json", "w", encoding="utf-8") as f:
json.dump(data, f)
从文件中读取json数据
with open("data.json", encoding="utf-8") as f:
data = json.load(f)
print(data)
关注公众号「Python之禅」,回复「1024」免费获取Python资源