【发布时间】:2014-08-09 17:09:10
【问题描述】:
我正在尝试打印这个使用 jason.loads 制作的 python 对象的 LineRef。
{
"Siri": {
"ServiceDelivery": {
"ResponseTimestamp": "2014-08-09T12:07:08.519-04:00",
"VehicleMonitoringDelivery": [
{
"VehicleActivity": [
{
"MonitoredVehicleJourney": {
"LineRef": "MTA NYCT_B38",
}
}
]
}
]
}
}
}
到目前为止,我已经编写了以下代码:
theJSON = json.loads(data)
for j in theJSON["VehicleMonitoringDelivery"]:
for i in theJSON["VehicleActivity"]:
print [i]["MonitoredVehicleJourney"]["LineRef"]
但它在 JSON 中给出错误
【问题讨论】:
-
“在 JSON 上给出错误”没有提供信息。什么错误?我们不是读心术的人。
-
如果你使用
python 3print [i]["MonitoredVehicleJourney"]["LineRef"]将会给你一个错误 -
@PadraicCunningham:它会在 Python 2 中产生同样多的错误。
-
@MartijnPieters,我指的是缺少括号
-
@PadraicCunningham:我知道,我指的是
[i]语法。
标签: python python-3.x json