在有效载荷发生变化之前,我的代码运行良好。
field_types = [
('subject', str),
('type', str)
]
#reading a raw csv file
output = []
with open('file.csv','r',encoding = 'utf-8-sig') as f:
for row in csv.DictReader(f):
row.update((key, conversion(row[key]))
for key, conversion in field_types)
output.append(row)
with open('file.json','w') as outfile: #storing records as json
json.dump(output,outfile,sort_keys = True, indent = 4)
结果保存的很好:
{
"subject": "1",
"type": "2"
},
{
"subject": "1",
"type": "3"
}
]
当前要求它应该保存为 ie 我猜是数组中的 jsonarray。你有过这种情况吗?如何实现?
{
"subject":
{
"id": "1"
},
"type": "2"
},
{
"subject":
{
"id": "1"
},
"type": "3"
}
]
四季花海
相关分类