python 读写json
- 将python dict 写入json文件
json.dump()
import json dict = {'a':1213,'b':['ad',3,'23fs']} with open("file_path", "w") as json_f: json.dump(dict, json_f)
- 读取json文件
- json.load()
import json() with open("file_path", "r") as json_f: dict = json.load(json_f)
- 将python字典转换成json字符串
- json.dumps()
import json dict = {'a':1213,'b':['ad',3,'23fs']} dict_str = json.dumps(dict)
- 将json字符串转换成python字典
- json.loads()
import json dict_str = '{'a':1213,'b':['ad',3,'23fs']}' dict = json.loads(dict_str)