Python 修改json file
import json def print_hi(name): print(f'Hi, {name}') if __name__ == '__main__': print_hi('PyCharm') updateValue = 12345 with open('jsonfile/create_mspc_bettypes.json') as file: json_data = json.load(file) for key, value in json_data.items(): # print(f'{key}={value}') if key == 'eventID': json_data['eventID'] = updateValue with open('jsonfile/create_mspc_bettypes.json', "w") as file2: json.dump(json_data, file2, ensure_ascii=False, indent = 2) # file2.write(json.dumps(json_data)) file2.close() file.close()