생활
파이썬에서 json 인덱싱에 어려움을 겪고있어 질문드립니다. ㅜㅜ
response = requests.get( url, headers=headers) match=response.json() print(match) print("_____") print(type(match)) print("_____") match =json.dumps(match) print(type(match)) print("_____") match = json.loads(str(match)) print(type(match)) print("_____") print(match) print("_____") print(match["matches"]["matches"]) print("_____")위와 같은 코드를 실행하고 나면 아래와 같이 실행이 되면서 마지막에 인덱싱 에러가 납니다.
{'matches': [{'matchType': 'free', 'matches': [{'accountNo': '636755761583559872', 'matchId': 'B7jP2vwWNK', 'matchType': 'free', 'teamId': 'north', 'characterName': 'Medusa', 'matchResult': 'lose', 'seasonType': '0', 'startTime': '2019-02-19T05:49:47', 'endTime': '2019-02-19T06:10:55'}]}]} _____ <class 'dict'> _____ <class 'str'> _____ <class 'dict'> _____ {'matches': [{'matchType': 'free', 'matches': [{'accountNo': '636755761583559872', 'matchId': 'B7jP2vwWNK', 'matchType': 'free', 'teamId': 'north', 'characterName': 'Medusa', 'matchResult': 'lose', 'seasonType': '0', 'startTime': '2019-02-19T05:49:47', 'endTime': '2019-02-19T06:10:55'}]}]} _____ print(match["matches"]["matches"]) TypeError: list indices must be integers or slices, not str위의 인덱싱 에러가 왜 발생되는지 모르겠어서 질문 드립니다. ㅜㅜ
1개의 답변이 있어요!