修改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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM