json文件保存:
import json
a = {"姓名":"model","age":17}
with open("information.json",'w',encoding='utf-8') as f:
json.dump(a,f,ensure_ascii=False)
json文件读取:
with open("information.json",'r',encoding='utf-8') as f:
model=json.load(f)
print(model)
注意:
json.dumps将一个Python数据结构转换为json串;json.dump() 是把python对象转换成json对象生成一个json文件。
import json
data = {"姓名":"model","age":17}
json_dic = json.dumps(data)
print(json_dic)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)