python读写json文件

#读取json文件
train_f = open('train_aug.json','r', encoding='UTF-8')
train = json.load(train_f)
#写入json文件
data1 = list()
file_root_path = 'test_images'
file_list = os.listdir(file_root_path)
file_list.sort()
file = open('test.json','w',encoding='utf-8')
for i in range(4959):
    data = {'image_id':file_list[i],"disease_class":int(class_set[i])}
    data1.append([data])
json.dump(data1,file,ensure_ascii=False)
file.close()
file = open('test.json','r',encoding='utf-8')
s = json.load(file)

 

你可能感兴趣的:(python读写json文件)