Hi,
I have the following Json I'm trying to loop through:
{"codea": "23DWDQW","request_time": "2018-01-05T16:44:24Z","lookingup": {"497": [{"mode": "transit","line": "497","aimed_time": "16:45" }, {"mode": "transit","line": "497","aimed_time": "16:45" } ],"T1": [{"mode": "transit","line": "T1","aimed_time": "15:45" }, {"mode": "transit","line": "T1","aimed_time": "15:45" } ],"324": [{"mode": "transit","line": "324","aimed_time": "16:45" }, {"mode": "transit","line": "324","aimed_time": "16:45" }, {"mode": "transit","line": "324","aimed_time": "16:53" } ] } }
After pulling in the json from an external source I'm doing the following:
JObject busData;
busData = JObject.Parse(busContents); // Tranverse to the "departures" token JToken buses = busData.SelectToken("departures"); string busNumber; foreach(JToken bus in buses.Children()) { // Get the Bus Number var busProperty = bus as JProperty; busNumber = busProperty.Name; Console.WriteLine("Bus Number: " + busNumber); }
The problem I'm having is getting to the data underneath "497", "T1" and "324"... IE the "mode", "line" and "aimed_time" elements. Mainly because "497", "T1" and "324" can have different values each and every time I call the service.
Can anyone point me in the right direction?
Thanks James