load
从外部JSON文件变成dict字典(外部文件一定要是json格式)json.load(open('a.json',"r"))
dump
把dict字典变成json格式,生成到外部文件里面json.dump(dict,open('a.json',"w"))
dumps
Convert Python Object (Dict) to JSON1
2
3
4
5
6
7
8import json
d = {}
d["Name"] = "Luke"
d["Country"] = "Canada"
print json.dumps(d, ensure_ascii=False)
# result {"Country": "Canada", "Name": "Luke"}
loads
To convert JSON to a Python dict use this:1
2
3
4
5
6import json
json_data = '{"name": "Brian", "city": "BJ"}'
python_obj = json.loads(json_data)
print python_obj["name"]
print python_obj["city"]