파이썬에서 json 인덱싱에 어려움을 겪고있습니다.. 초보적인 문제같은데
조회수 1230회
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
댓글 입력