1
我試圖在Python中提取各個路徑ID。獲取JSON密鑰錯誤
當我打印route_id
在data['route']
我收到KeyError:'route'
。這是什麼意思?我看到有一個數組'mode'
和另一個數組'route'
。
這是JSON數據:
{ "mode":[
{
"route_type":"0",
"route":[
{
"route_id":"Green-B",
"route_name":"Green Line B"
},
{
"route_id":"Green-C",
"route_name":"Green Line C"
},
{
"route_id":"Green-D",
"route_name":"Green Line D"
},
{
"route_id":"Green-E",
"route_name":"Green Line E"
},
{
"route_id":"Mattapan",
"route_name":"Mattapan Trolley"
}
],
"mode_name":"Subway"
},
'data [「mode」] [0] [「route」] [0] [「route_id」]' – ppaulojr
謝謝你們倆! –
陌生人:請閱讀[_當某人回答我的問題時該怎麼辦?_(http://stackoverflow.com/help/someone-answers) – martineau