#将字典转json并写入文件 import json i=3 j=5 a={‘a‘:i,‘b‘:j} js=json.dumps(a) print(js) with open("/Users/binwang/Downloads/test/result.json", "w") as fp: fp.write(js) ----------------------------------------------------------------------
#读取json文件并转换为dict
with open(os.path.abspath(os.path.dirname(__file__)) + ‘/metadata_center_v2.json‘) as r: data = json.loads(r.read())
原文地址:https://www.cnblogs.com/wangbin2188/p/12034324.html
时间: 2024-11-08 10:02:06