dumps
# json.dumps()函数的使用,将字典转化为字符串
dict1 = {"age": "12"} #type:dict
json_info = json.dumps(dict1)# type:str
loads
# json.loads函数的使用,将字符串转化为字典
json_info = '{"age": "12"}'#type:str,不允许是dict
dict1 = json.loads(json_info)#type:json
dump
# json.dump()函数的使用,将json信息写进文件
json_info = "{'age': '12'}"#type:str
file = open('1.json','w',encoding='utf-8')
json.dump(json_info,file)
json_info = {'age': '12'}#type:dict
file2 = open('2.json','w',encoding='utf-8')
json.dump(json_info,file2)
load
# json.load()函数的使用,将读取json信息
file = open('1.json','r',encoding='utf-8')
info = json.load(file)#type(info)=dict