python - Getting certain information from string -
i'm new python wondering how estimatedwait
, routename
string.
{ "lastupdated": "07:52", "filterout": [], "arrivals": [ { "routeid": "b16", "routename": "b16", "destination": "kidbrooke", "estimatedwait": "due", "scheduledtime": "06: 53", "isrealtime": true, "iscancelled": false }, { "routeid":"b13", "routename":"b13", "destination":"new eltham", "estimatedwait":"29 min", "scheduledtime":"07:38", "isrealtime":true, "iscancelled":false } ], "servicedisruptions":{ "infomessages":[], "importantmessages":[], "criticalmessages":[] } }
and save string displayed on lxterminal
of raspberry pi 2. 'routename' of b16 saved string. how do that?
you have deserialise object , use index access data want.
to find b16
entries can filter arrivals list.
import json obj = json.loads(json_string) # filter b16 objects b16_objs = filter(lambda a: a['routename'] == 'b16', obj['arrivals']) if b16_objs: # first item b16 = b16_objs[0] my_estimatedwait = b16['estimatedwait'] print(my_estimatedwait)
Comments
Post a Comment