Python 读写 json 文件

import json


# 读取 json

after = []
with open("1.json", 'r') as f:
    data = json.load(f)

    print(type(data))

    after = data


# 修改相应值

for k in range(len(after)):  
    after[k]['scale_provided'] = 1.0
    after[k]['numOtherPeople'] = 0.000
    after[k]['people_index'] = 1.000 
    after[k]['isValidation'] = 0.0

# 保存到新 json 中

file = open("2.json", 'w')
file.write(json.dumps(after))
file.close()

print(after[0])

 

 

你可能感兴趣的:(Python)