json.load()从文件中读取json字符串 json.loads()将json字符串转换为字典类型 json.dumps()将python中的字典类型转换为字符串类型 json.dump()将json格式字符串写到文件中 1.json.load() with open('text.json','r',encoding='utf-8') as f : print(json.load(f)) { "name": "anthony", "sex"
import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转化为字符串 # json_str = json.dumps(data) # fw.write(json_str) # 上面两句等同于下面这句 json.dump(data,fw) # load json data from file def load(): with open('data.json'