dict2json_file() 將字典存儲為json文件。
dict2json_file() 接收兩個參數(shù),第一個參數(shù)為要存儲的數(shù)據(jù),第二個參數(shù)為存放的路徑+文件名。
以下是 dict2json_file() 的語法:
dict2json_file(dict, file='temp/temp.json')
● dict [dict]:要存儲的字典數(shù)據(jù)。
● file [str]:要儲存的路徑+文件名。
無返回值。
以下展示了使用 dict2json_file() 的實例:
from kyger.utility import dict2json_file print(dict2json_file({"name": "kgcms", "www": "http://bfraz.cn"}, file='static/kgcms.json')) # 將字典轉(zhuǎn)成json寫入到文件
以上實例運行后輸出的結(jié)果為:
# static/kgcms.json文件內(nèi)容:{"name": "kgcms", "www": "http://bfraz.cn"}