【发布时间】:2018-08-04 09:26:53
【问题描述】:
这是我的代码:
import requests
import json
res = requests.get("http://transport.opendata.ch/v1/connections?
from=Baldegg_kloster&to=Luzern&fields[]=connections/from/prognosis/departure")
parsed_json = res.json()
print(parsed_json['connections']['from']['prognosis'])
"departure"
但是,如果我运行它,我会收到以下错误:
Traceback (most recent call last):
File "/home/pi/Desktop/Matura/v7/v7_test.py", line 10, in <module>
print(parsed_json['connections']['from']['prognosis'])
TypeError: list indices must be integers or slices, not str
我查看了其他类似的问题,但没有找到解决方案 我是编码新手,所以我不知道问题出在哪里。
【问题讨论】:
-
res.json()里面是什么?
标签: python arrays list error-handling raspberry-pi