1. 程式人生 > >json檔案儲存與讀取

json檔案儲存與讀取

一、將資料儲存為.json檔案

1 model={} #資料
2 with open("./hmm.json",'w',encoding='utf-8') as json_file:
3         json.dump(model,json_file,ensure_ascii=False)
4  

二、讀取.json檔案

1 model={} #存放讀取的資料
2 with open("./hmm.json",'r',encoding='utf-8') as json_file:
3         model=json.load(json_file)

三、dict資料儲存不用轉化成json,讀取json資料也不能轉dict資料