修改json文件

 

import os,json

f = 'D:\\temp\\userlist.json'
f2 = 'D:\\temp\\userlist2.json'

file = open(f,'rb')
fj = json.load(file)
file.close()

fj['liu'].remove('liu.ad3')
fj['liu'].append('liu.ad4')
# print(fj['liuchao6'])
fname = 'wangwu'
fj[fname]=['eae']
# dict_new = {'zhangsan':['abc']}
# fj.update(dict_new)
jsonfile = json.dumps(fj)
print(jsonfile)
# print(jsonfile)
with open(f2,'w') as fw:
    fw.write(jsonfile)

 

posted on 2019-12-11 18:16  momingliu11  阅读(3127)  评论(0编辑  收藏  举报