I have some json for live bus stop arrivals and departures.
{
"atcocode": "269030083",
"smscode": "lecdgpja",
"request_time": "2019-05-25T13:45:14+01:00",
"name": "St Margaret's Bus Station (Stand SM)",
"stop_name": "St Margaret's Bus Station",
"bearing": "",
"indicator": "Stand SM",
"locality": "Leicester",
"location": {
"type": "Point",
"coordinates": [
-1.1339,
52.6397
]
},
"departures": {
"153": [
{
"mode": "bus",
"line": "153",
"line_name": "153",
"direction": "Market Bosworth, Terminus (unmarked)",
"operator": "AMID",
"date": "2019-05-25",
"expected_departure_date": null,
"aimed_departure_time": "13:45",
"expected_departure_time": null,
"best_departure_estimate": "13:45",
"source": "NextBuses",
"dir": "outbound",
"id": "https://transportapi.com/v3/uk/bus/route/AMID/153/outbound/269030083/2019-05-25/13:45/timetable.json?app_id=ID&app_key=KEY",
"operator_name": "Arriva Midlands"
},
{
"mode": "bus",
"line": "153",
"line_name": "153",
"direction": "Market Bosworth, Terminus (unmarked)",
"operator": "AMID",
"date": "2019-05-25",
"expected_departure_date": null,
"aimed_departure_time": "14:45",
"expected_departure_time": null,
"best_departure_estimate": "14:45",
"source": "NextBuses",
"dir": "outbound",
"id": "https://transportapi.com/v3/uk/bus/route/AMID/153/outbound/269030083/2019-05-25/14:45/timetable.json?app_id=ID&app_key=KEY",
"operator_name": "Arriva Midlands"
},
{
"mode": "bus",
"line": "153",
"line_name": "153",
"direction": "Market Bosworth, Terminus (unmarked)",
"operator": "AMID",
"date": "2019-05-25",
"expected_departure_date": null,
"aimed_departure_time": "15:45",
"expected_departure_time": null,
"best_departure_estimate": "15:45",
"source": "NextBuses",
"dir": "outbound",
"id": "https://transportapi.com/v3/uk/bus/route/AMID/153/outbound/269030083/2019-05-25/15:45/timetable.json?app_id=ID&app_key=KEY",
"operator_name": "Arriva Midlands"
}
]
},
"source": "NextBuses"
}
In this example departures has a member "153" but obviously as the bus names change, the member name will change for example to "N1" etc.
What I have tried:
I have tried making depatures a dictionary but when I foreach through the dictionary I just get null values....
public class Departures
{
public Dictionary<string, listing_details> listing { get; set; }
}
public class listing_details
{
public string mode { get; set; }
public string line { get; set; }
public string line_name { get; set; }
public string direction { get; set; }
public string @operator { get; set; }
public string date { get; set; }
public string expected_departure_date { get; set; }
public string aimed_departure_time { get; set; }
public string expected_departure_time { get; set; }
public string best_departure_estimate { get; set; }
public string source { get; set; }
public string dir { get; set; }
public string id { get; set; }
public string operator_name { get; set; }
}
Can someone suggest how I would iterate through different name bus lists please? In this example it will be departures.153 but for the N1 bus but it might be departures.N1 . Sadly I won't know the bus names until I get the JSON so I am competely perplexed. Any help would be appreciated! Thanks.