I'm making a program that extracts MTA Bus Time Info. The json I get for a specific bus looks like
{u'VisitNumber': 1, u'StopPointRef': u'MTA_403111', u'ExpectedDepartureTime': u'2016-06-26T21:25:34.806-04:00', u'StopPointName': u'BROADWAY/W 91 ST', u'Extensions': {u'Distances': {u'CallDistanceAlongRoute': 4378.49, u'StopsFromCall': 5, u'PresentableDistance': u'0.6 miles away', u'DistanceFromCall': 1038.43}}, u'ExpectedArrivalTime': u'2016-06-26T21:25:34.806-04:00'}
To make this easier to look at, I got the keys from it and they are
[u'VisitNumber', u'StopPointRef', u'ExpectedDepartureTime', u'StopPointName', u'Extensions', u'ExpectedArrivalTime']
I am attempting to reference the ExpectedArrivalTime
key in this function:
def getBusArrivalTime(bus):
return bus["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedArrivalTime"]
The json noted previously is the equivalent of bus["MonitoredVehicleJourney"]["MonitoredCall"]
, but when I try to reference ExpectedArrivalTime
, it gives me this error:
KeyError: 'ExpectedArrivalTime'
Is there something about json that I'm missing?
Aucun commentaire:
Enregistrer un commentaire