import json dic = {"name":"liao","age":18} data = json.dumps(dic) #转化为json字符串 print(data) #===>{"name": "liao", "age": 18} print(type(data)) #===> <class 'str'> #字符串 f = open("json1","w") f.write(data) f.close() f1 = open("json1","r") r = f1.read() #读出来的是字符串 print(json.loads(r)) #===> {'name': 'liao', 'age': 18} #通过json转为字典 print(type(json.loads(r))) #===><class 'dict'> #字典 f1.close()