python新手,試圖將json文件轉換爲csv,並在代碼中寫下,但不斷收到「TypeError:字符串索引必須是整數」錯誤。請建議。錯誤:TypeError:字符串索引必須是整數
import json
import csv
#x= '''open("Test_JIRA.json","r")'''
#x = json.load(x)
with open('Test_JIRA.json') as jsonfile:
x = json.load(jsonfile)
f = csv.writer(open("test.csv", "w"))
# Write CSV Header, If you dont need that, remove this line
f.writerow(["id", "self", "key", "customfield_12608", "customfield_12607"])
for x in x:
f.writerow([x["id"],
x["self"],
x["key"],
x["fields"]["customfield_12608"],
x["fields"]["customfield_12607"]
])
下面是示例1行輸入JSON文件中的數據:
{"expand":"schema,names","startAt":0,"maxResults":50,"total":100,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"883568","self":"https://jira.xyz.com/rest/api/2/issue/223568","key":"AI-243","fields":{"customfield_22608":null,"customfield_12637":"2017-10-12T21:46:00.000-0700"}}]}
你可以請加輸入JSON文件和輸出錯誤,因爲它是在控制檯 – RejeeshChandran
所示,請提供完整的回溯。 – Reti43