hsnam95 / class2022Spring

130 stars 21 forks source link

TypeError: string indices must be integers #21

Open saeonbaek opened 2 years ago

saeonbaek commented 2 years ago

https://colab.research.google.com/drive/1gpdD0K7z4SlhsUhTW7o6JNBIKpBlKbDe#scrollTo=mH941qOSGOF0

안녕하세요. 2019130818 백새온입니다. URL = ('http://apis.data.go.kr/3130000/openapi/tourDest/gettourDest?serviceKey=TlcXn777i%2Bhr0EAHUj%2B%2Fa1kuURjjes4xe%2F7nG8QRokc6yPxDmQKf1cV1iIvGt3yDj1FMvL%2F6ugoBd6imTZcR1g%3D%3D&type=json&filterKey=mapo_hotspot&filterValues=연트럴파크&numOfRows=200&pageNo=0') response = requests.get(URL)

r = response.json() r

{'items': [{'actual_area': '228210.76', 'address': '서울시 마포구 연남동 375일대', 'mapo_hotspot': '연트럴파크', 'naver_area': '30878.7', 'no_SNS_comment': '32735', 'no_awareness_reponse': '534', 'no_store': '785', 'no_turist': '36557963', 'number': '1', 'store_alley_extention': '4785.13'}], 'numOfRows': 200, 'pageNo': 0, 'resultCode': '0', 'resultMsg': 'SUCCESS', 'totalCount': 1}

여기까지는 잘 되었으나,

tems = r['items'][0]

address = [item['address'] for item in items]

이 부분에서 TypeError: string indices must be integers 오류가 뜨는데 고민해 보았으나 잘 모르겠습니다!

hsnam95 commented 2 years ago

items = r['items'] address = [item['address'] for item in items]

saeonbaek commented 2 years ago

잘 해결되었습니다! 감사합니다