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'
Python load json file with UTF-8 BOM header - Stack Overflow 3 down vote Since json.load(stream) uses json.loads(stream.read()) under the hood, it won't be that bad to write a small hepler function that lstrips the BOM: from codecs import BOM_UTF8 de