这是我的代码隐藏json到csv。
import csv
import json
with open('Documents/SampleCSVStory.csv', 'r') as f:
reader = csv.reader(f, delimiter=';')
data_list = list()
for row in reader:
data_list.append(row)
data = [dict(zip(data_list[0],row)) for row in data_list]
data.pop(0)
s = json.dumps(data)
print (s)
但输出就像这样
[{"Id,Name,Description": "1,User 1,Python Developer"}
我的期望是
[{"Id:"1",Name:"User 1",Description:"Python Developer"}
任何人都可以帮助我。?
答案 0 :(得分:0)
import csv
import json
with open('Documents/SampleCSVStory.csv', 'r') as f:
reader = csv.DictReader(f, delimiter=';')
json.dumps([row for row in reader])