我想加载JSON文件并更改特定的键值,然后将更新的条目保存到新文件。这个JSON文件具有许多具有相同格式的条目。这是我在来这里之前最远的尝试,但它不能保存新的价值。在Python中修改JSON键值
我错过了什么?
#!/usr/bin/python
import simplejson as json
import names
in_file = open('Names.json', 'r')
out_file = open('Names_new.json','w')
data_file = in_file.read()
data = json.loads(data_file)
for x in data:
nickname = x['nickname']
newname = names.get_first_name()
nickname = newname
out_file.write(json.dumps(data))
out_file.close()
真棒,感谢工作就像一个魅力 – user10847