我正在學(xué)習(xí)python并試圖將github問(wèn)題轉(zhuǎn)換為可讀形式。使用有關(guān)如何將JSON轉(zhuǎn)換為CSV的建議?我想出了這個(gè):import jsonimport csvf=open('issues.json')data = json.load(f)f.close()f=open("issues.csv","wb+")csv_file=csv.writer(f)csv_file.writerow(["gravatar_id","position","number","votes","created_at","comments","body","title","updated_at","html_url","user","labels","state"])for item in data: csv_file.writerow([item["gravatar_id"], item["position"], item["number"], item["votes"], item["created_at"], item["comments"], item["body"], item["title"], item["updated_at"], item["html_url"], item["user"], item["labels"], item["state"]])其中“ issues.json”是包含我的github問(wèn)題的json文件。當(dāng)我嘗試運(yùn)行它時(shí),我得到File "foo.py", line 14, in <module>csv_file.writerow([item["gravatar_id"], item["position"], item["number"], item["votes"], item["created_at"], item["comments"], item["body"], item["title"], item["updated_at"], item["html_url"], item["user"], item["labels"], item["state"]])TypeError: string indices must be integers我在這里想念什么?哪些是“字符串索引”?我確定一旦完成這項(xiàng)工作,我就會(huì)遇到更多問(wèn)題,但是就目前而言,我只是希望它能正常工作!更新: 當(dāng)我調(diào)整for語(yǔ)句以簡(jiǎn)單地for item in data: print item我得到的是...“問(wèn)題”-所以我在做一些更基本的錯(cuò)誤。這是我的json:{"issues":[{"gravatar_id":"44230311a3dcd684b6c5f81bf2ec9f60","position":2.0,"number":263,"votes":0,"created_at":"2010/09/17 16:06:50 -0700","comments":11,"body":"Add missing paging (Older>>) links...當(dāng)我打印時(shí)data,看起來(lái)好像真的很奇怪:{u'issues': [{u'body': u'Add missing paging (Older>>) lin...
查看完整描述