我想從此API獲取stopId,但我很難使用retrofit 2 + gson解析它。我只有使用較簡單的JSON API的經驗。任何人都可以幫我嗎?如何在Android Studio中解析複雜的JSON與Retrofit 2
{
"direction": "inbound",
"timetable": {
"$type": "Tfl.Api.Presentation.Entities.Timetable, Tfl.Api.Presentation.Entities",
"departureStopId": "940GZZCRECR",
"routes": [{
"$type": "Tfl.Api.Presentation.Entities.TimetableRoute, Tfl.Api.Presentation.Entities",
"stationIntervals": [{
"$type": "Tfl.Api.Presentation.Entities.StationInterval, Tfl.Api.Presentation.Entities",
"id": "0",
"intervals": [{
"$type": "Tfl.Api.Presentation.Entities.Interval, Tfl.Api.Presentation.Entities",
"stopId": "940GZZCRLEB",
"timeToArrival": 2
}, {
"$type": "Tfl.Api.Presentation.Entities.Interval, Tfl.Api.Presentation.Entities",
"stopId": "940GZZCRSAN",
"timeToArrival": 3
}]
}, {
}, {
}],
"schedules": [
]
}]
}
}
我想過這個,但我想可能有更好的方法來做到這一點。但是,這似乎很好!當我實施它時,我會給你一個機會,它會起作用。 –
另外,你可以創建自定義的'TypeAdapter',並實現自己的解析你的json的機制,但我不建議你這樣做。 –
我不斷收到這個錯誤'預計BEGIN_ARRAY,但是在BEGIN_OBJECT行1列2'。然而,我正在使用的API [鏈接](https://api.tfl.gov.uk/Line/tram/Timetable/940GZZCRECR?direction=inbound&app_id=&app_key=) –