直接上代码:标签:__,load,package,Python,json,file,Test,data From: https://www.cnblogs.com/GlCh/p/17903070.html
import json
def json_load(json_file):
with open(json_file, 'r') as fh:
content = json.load(fh)
return content
fh.close()
def json_save(json_file, data):
with open(json_file,'w',encoding='UTF-8') as f:
json.dump(data, f)
f.close()
def modify_json():
json_file = 'C:\Python\\assets\config.json'
data = json_load(json_file)
data['auth']['clientId'] = "Test ClientID"
data['auth']['authority'] = "Test authority"
data['auth']['scopes'] = "Test scopes"
json_save(json_file, data)
if __name__ == '__main__':
modify_json()