Answer the question
In order to leave comments, you need to log in
How to output JSON values correctly?
When working with the scheduling API, JSON comes. I parsed it out with print(result['threads']):
[{'duration': 35940.0, 'departure_platform': '', 'thread': {'number': '247S', 'uid': '247S_1_2', 'vehicle': None, 'express_type': None, 'title ': 'Anapa - Saint Petersburg', 'carrier': {'code': 112, 'title': 'RZD/FPK', 'codes': {'sirena': None, 'iata': None, 'icao ': None}}, 'short_title': 'Anapa - Saint Petersburg', 'transport_type': 'train'}, 'departure': '2017-09-04 02:38:00', 'arrival_terminal': None, 'arrival': '2017-09-04 12:37:00', 'from': {'code': 's9604798', 'station_type': 'station', 'title': 'Lipetsk', 'type': 'station', 'short_title':'', 'popular_title': '', 'transport_type': 'train'}, 'departure_terminal': None, 'arrival_platform': '', 'stops': '', 'to': {'code': 's2000001 ', 'station_type': 'station', 'title': 'Moscow (Kursky railway station)', 'type': 'station', 'short_title': 'M-Kurskaya', 'popular_title': 'Kursky railway station', ' transport_type': 'train'}}, {'duration': 39960.0, 'departure_platform': '', 'thread': {'number': '562S', 'uid': '562S_1_2', 'vehicle': None, 'express_type': None, 'title': 'Yeisk — Moscow', 'carrier': {'code': 112, 'title': 'RZD/FPK', 'codes': {'sirena': None, 'iata': None, 'icao': None}}, 'short_title': 'Yeysk — Moscow', 'transport_type': 'train'}, 'departure': '2017- 09-04 04:40:00', 'arrival_terminal': None, 'arrival': '2017-09-04 15:46:00', 'from': {'code': 's9604798', 'station_type': 'station', 'title': 'Lipetsk', 'type': 'station', 'short_title': '', 'popular_title': '', 'transport_type': 'train'}, 'departure_terminal': None, ' arrival_platform': '', 'stops': '', 'to': {'code': 's2000001', 'station_type': 'station', 'title': 'Moscow (Kursk railway station)', 'type':'station', 'short_title': 'M-Kurskaya', 'popular_title': 'Kursky railway station', 'transport_type': 'train'}}, {'duration': 35520.0, 'departure_platform': ''.... .}}]
I do not know how to process and display specific values for each individual train in the form: Departure time, train number, train name.
Answer the question
In order to leave comments, you need to log in
import json
a = json.loads("{}");
print a
print a.keys();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question