json数据格式和读写方法
json数据格式
值用[x1,x2,..]表示,
键值对用{x:,y:}
json读写
json文件与dict
读取json:
import json
f = open('static/data/newsTest.json','rb')
data = json.load(f)
存为json:
with open("../config/record.json","w") as f:
json.dump(new_dict,f)
print("加载入文件完成...")
json字符串与dict
dict转字符串:
test_dict = {'bigberg': [7600, {1: [['iPhone', 6300], ['Bike', 800], ['shirt', 300]]}]}
json_str = json.dumps(test_dict)
字符串转dict:
new_dict = json.loads(json_str)