python中json文件的读取与保存
项目需要,写了一个读取保存函数,实现的是互换json文件的某两个dict
import json
def changeValue(filepath):
with open(filepath,encoding='utf-8') as f:
myjson=json.load(f)
for item in range(len(myjson)):#因为有不同的对象在json文件中
temp=myjson[item]['videourl']
myjson[item]['videourl']= myjson[item]['videofileID']
myjson[item]['videofileID']=temp
#保存
with open(filepath, 'w') as fw:
json.dump(myjson,fw)
return
if __name__== "__main__":
changeValue('cms-data-export-2021-01-11.json')