我很新的编程,已经从过去3/4周学习python和 这是给定的任务之一。csv到json转换与python
输入
A, B, C, D
1, 2, 3, 4
5, 6, 7, 8
输出
{{A:”1”, B:”2”, C:”3”, D:”4”}, {A:”5”, B:”6”, C:”7”, D:”8”}}
我一直在试图与代码
import csv
import json
csvfile = open('test.csv','r')
jsonfile = open('test.json','w')
x = ("a","b","c","d")
reader = csv.DictReader(csvfile, x)
for row in reader:
json.dump(row, jsonfile)
此代码的输出之际,下面
{"a": "1", "null": ["5", "6", "7", "8", "9"], "c": "3", "b": "2", "d": "4"}
任何人都可以帮助我解决这个问题。 TIA
输入在CSV文件。输出不是有效的json。你的意思是字典清单? '[{A:“1”,B:“2”,C:“3”,D:“4”},{A:“5”,B:“6”,C:“7”,D: 8“}]' – falsetru
对不起..是的这是列表 – naren