저는 파이썬과 코딩에 익숙하지 만, 어쨌든 Imgur API를 함께 묶어서 JSON 출력 파일을 제공하는 방법을 알았습니다. 내 최종 목표는 이미 다른 수집 된 데이터와 함께 Excel에 파일을 넣을 수 있기 때문에 API 출력을 CSV로 변환 할 수 있기를 바랍니다. - 지금까지 유일한 해결책은 JSON 출력을 가져 와서 온라인 변환기에 넣는 것입니다. (다른 사람들이 온라인에서 말한 것을 시도했지만 결코 작동시킬 수 없었습니다.)Python Imgur API CSV 로의 JSON 출력
다음은 예제 출력입니다. json으로 (내가 어떤 중첩 된 부분이없는 확신) :
{"status": 200, "data": {"in_gallery": false, "deletehash": "pfSgnqtf9eh4r2B", "layout": "blog", "description": null, "title": null, "cover_height": 177, "views": 0, "privacy": "public", "cover": "P1tTbZw", "images_count": 2, "datetime": 1468959627, "account_url": "JosephL32", "favorite": false, "cover_width": 222, "link": "http://imgur.com/a/3I3H7", "is_ad": false, "section": null, "images": [{"datetime": 1468959628, "bandwidth": 0, "nsfw": null, "vote": null, "id": "P1tTbZw", "account_id": null, "in_gallery": false, "title": null, "section": null, "width": 222, "size": 48248, "type": "image/png", "is_ad": false, "deletehash": "mGqP4DFgDtBZG8Y", "description": null, "views": 0, "link": "http://i.imgur.com/P1tTbZw.png", "height": 177, "name": "Screen Shot 2016-07-19 at 4.20.05 PM", "favorite": false, "account_url": null, "animated": false}, {"datetime": 1468959630, "bandwidth": 0, "nsfw": null, "vote": null, "id": "5zGa1go", "account_id": null, "in_gallery": false, "title": null, "section": null, "width": 221, "size": 74481, "type": "image/png", "is_ad": false, "deletehash": "LnJxl5rltxsIFl2", "description": null, "views": 0, "link": "http://i.imgur.com/5zGa1go.png", "height": 152, "name": "Screen Shot 2016-07-19 at 4.19.59 PM", "favorite": false, "account_url": null, "animated": false}], "nsfw": null, "id": "3I3H7", "account_id": 37918982}, "success": true}
내가로 저장하는 내가 JSON 데이터를받은 후 삽입 할 수 있습니다 파이썬 코드를 찾고 있어요 그것을 요약하면 CSV 파일.
고맙습니다.
감사합니다. 나는 파이썬 2.7에있다. 파일을 실행할 때 json 디코더를 가리키는 오류가 발생합니다 : 에서'File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py"339 행 return _default_decoder.decode (s) 파일 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", 줄 364, 디코드 obj, 끝 = self.raw_decode s, idx = _w (s, 0) .end()) ' –
문제가 없습니다! OS X의 Python 2.7에서 코드를 테스트했는데,이 플랫폼은 현재 사용중인 플랫폼과 같습니다. 오류가 발생하지 않았습니다. 그래도 전체 오류 메시지가 확실합니까? 보통 'TypeError : ...'와 같은 스택 추적 아래에 더 유익한 메시지가 있습니다. –
업데이트 : 오류 텍스트를 찾아서이 [StackOverflow 게시물] (http://stackoverflow.com/questions/36387302/why-am-i-getting-decoder-errors-when-turning-my-json-array-into- a-python-list-us). 'json.loads()'에 전달하는 것이 실제로는 문자열인지 아닌지 확인하십시오. –