【发布时间】:2014-10-07 01:16:44
【问题描述】:
我正在使用返回以下 JSON 的服务:
{
"Airport Terminal A Departures: October 6, 2014, 8:31 pm": [
{
"Northbound": [
{
"direction": "N",
"path": "R4N",
"train_id": "462",
"origin": null,
"destination": "Warminster",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 08:43:00:000PM",
"depart_time": "Oct 6 2014 08:43:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "9464",
"origin": null,
"destination": "Temple U",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 09:13:00:000PM",
"depart_time": "Oct 6 2014 09:13:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "466",
"origin": null,
"destination": "Warminster",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 09:43:00:000PM",
"depart_time": "Oct 6 2014 09:43:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "9468",
"origin": null,
"destination": "Temple U",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 10:13:00:000PM",
"depart_time": "Oct 6 2014 10:13:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "470",
"origin": null,
"destination": "Warminster",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 10:43:00:000PM",
"depart_time": "Oct 6 2014 10:43:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "9472",
"origin": null,
"destination": "Temple U",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 11:13:00:000PM",
"depart_time": "Oct 6 2014 11:13:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "474",
"origin": null,
"destination": "Warminster",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 11:43:00:000PM",
"depart_time": "Oct 6 2014 11:43:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "N",
"path": "R4N",
"train_id": "476",
"origin": null,
"destination": "Glenside",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 7 2014 12:13:00:000AM",
"depart_time": "Oct 7 2014 12:13:00:000AM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
}
]
},
{
"Southbound": [
{
"direction": "S",
"path": "R4S",
"train_id": "463",
"origin": "Warm",
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": "30th Street Station",
"sched_time": "Oct 6 2014 08:49:00:000PM",
"depart_time": "Oct 6 2014 08:49:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "465",
"origin": "Warm",
"destination": "Airport",
"status": "1 min",
"service_type": "LOCAL",
"next_station": "Glenside",
"sched_time": "Oct 6 2014 09:19:00:000PM",
"depart_time": "Oct 6 2014 09:19:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "9467",
"origin": null,
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 09:49:00:000PM",
"depart_time": "Oct 6 2014 09:49:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "469",
"origin": null,
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 10:19:00:000PM",
"depart_time": "Oct 6 2014 10:19:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "9471",
"origin": null,
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 10:49:00:000PM",
"depart_time": "Oct 6 2014 10:49:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "473",
"origin": null,
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 11:19:00:000PM",
"depart_time": "Oct 6 2014 11:19:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
},
{
"direction": "S",
"path": "R4S",
"train_id": "9475",
"origin": null,
"destination": "Airport",
"status": "On Time",
"service_type": "LOCAL",
"next_station": null,
"sched_time": "Oct 6 2014 11:49:00:000PM",
"depart_time": "Oct 6 2014 11:49:00:000PM",
"track": "2",
"track_change": null,
"platform": " ",
"platform_change": null
}
]
}
]
}
如果更容易查看,您可以在http://www3.septa.org/hackathon/Arrivals/90404/10/ 查看 JSON。 看起来根节点是动态的并带有时间戳。我想访问“北向”和“南向”节点中的信息。但是,我能够找到的每个示例都使用根节点并通过它访问子节点。由于这种情况下的根节点是自动生成并带有时间戳的,因此我不确定如何访问子节点。
我知道以下将正确返回“N”:
data['Airport Terminal A Departures: October 6, 2014, 8:31 pm'][0].Northbound[0].direction;
我确定我遗漏了一些明显的东西。非常感谢您的帮助。
【问题讨论】:
-
尝试至少使用多行格式化,这样更容易阅读...
-
很抱歉。完成。
-
root节点的root是什么?