Вы можете попробовать это следующим образом:
Вам нужно будет передать свой ответ, и я просто поместил весь ваш ответ в String
.Вы можете передать свой собственный ответ от API от этого имени.
String response="[{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"bakerloo\",\"name\":\"Bakerloo\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.303Z\",\"modified\":\"2018-12-11T17:06:05.303Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Bakerloo&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"central\",\"name\":\"Central\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.3Z\",\"modified\":\"2018-12-11T17:06:05.3Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Central&serviceTypes=Regular\"},{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Night\",\"uri\":\"/Line/Route?ids=Central&serviceTypes=Night\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"circle\",\"name\":\"Circle\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.3Z\",\"modified\":\"2018-12-11T17:06:05.3Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Circle&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"district\",\"name\":\"District\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.3Z\",\"modified\":\"2018-12-11T17:06:05.3Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=District&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"dlr\",\"name\":\"DLR\",\"modeName\":\"dlr\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.303Z\",\"modified\":\"2018-12-11T17:06:05.303Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=DLR&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"hammersmith-city\",\"name\":\"Hammersmith & City\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.297Z\",\"modified\":\"2018-12-11T17:06:05.297Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Hammersmith & City&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"jubilee\",\"name\":\"Jubilee\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.297Z\",\"modified\":\"2018-12-11T17:06:05.297Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Jubilee&serviceTypes=Regular\"},{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Night\",\"uri\":\"/Line/Route?ids=Jubilee&serviceTypes=Night\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"metropolitan\",\"name\":\"Metropolitan\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.297Z\",\"modified\":\"2018-12-11T17:06:05.297Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Metropolitan&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"northern\",\"name\":\"Northern\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.3Z\",\"modified\":\"2018-12-11T17:06:05.3Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Northern&serviceTypes=Regular\"},{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Night\",\"uri\":\"/Line/Route?ids=Northern&serviceTypes=Night\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"piccadilly\",\"name\":\"Piccadilly\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.3Z\",\"modified\":\"2018-12-11T17:06:05.3Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Piccadilly&serviceTypes=Regular\"},{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Night\",\"uri\":\"/Line/Route?ids=Piccadilly&serviceTypes=Night\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"victoria\",\"name\":\"Victoria\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.297Z\",\"modified\":\"2018-12-11T17:06:05.297Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Victoria&serviceTypes=Regular\"},{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Night\",\"uri\":\"/Line/Route?ids=Victoria&serviceTypes=Night\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}},{\"$type\":\"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities\",\"id\":\"waterloo-city\",\"name\":\"Waterloo & City\",\"modeName\":\"tube\",\"disruptions\":[],\"created\":\"2018-12-11T17:06:05.297Z\",\"modified\":\"2018-12-11T17:06:05.297Z\",\"lineStatuses\":[],\"routeSections\":[],\"serviceTypes\":[{\"$type\":\"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities\",\"name\":\"Regular\",\"uri\":\"/Line/Route?ids=Waterloo & City&serviceTypes=Regular\"}],\"crowding\":{\"$type\":\"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities\"}}]\n";
try {
JSONArray jsArray=new JSONArray(response);
for(int i=0;i<jsArray.length();i++)
{
String id=jsArray.getJSONObject(i).getString("id");
String name=jsArray.getJSONObject(i).getString("name");
}
} catch (JSONException ex) {
ex.printStackTrace();
}
Это даст вам id
и name