Я работаю над проектом, который ранее делал другой разработчик. Я продолжаю называть API для проекта. Я пошел по его пути. Но я застреваю, когда хочу получить JsonArray
и показать его в RecyclerView
.
Как я могу получить данные от JSONArray
.
Интерфейс:
interface TripService {
@FormUrlEncoded
@POST("driver/getAvailableTripList")
fun availableTripList(@Field("page") page : String): Call<JsonObject>
}
TripServiceHandler:
class TripServiceHandler {
private var instance: TripService? = null
// Singleton instance to access through the application
init {
if(instance == null) {
instance = TripFactory().createJourney(TripService::class.java)
}
}
// Method for Driver Balance Service
fun availableTripList(page: String, listener: ServerCallbackListener) =
this.instance?.let {this.instance!!.availableTripList(page).enqueue(RetrofitCallBackHandler.getHandler(listener))
}
Фрагмент:
private fun getAvailableTrip(){
showLoading()
TripServiceHandler().availableTripList("1", availableTripHandler)
}
private var availableTripHandler: ServerCallbackListener = object : ServerCallbackListener {
override fun onSuccess(baseResponse: JsonObject?) {
hideLoading()
val data = baseResponse!!.getAsJsonObject(AppConstants.KEY_DATA)
}
override fun onFailure(message: String?) {
showMessageBar(message, SnackBarUtility.MessageType.ERROR)
}
}
Модель данных:
class Trip : Serializable {
@SerializedName("tid")
var tripId: String? = null
@SerializedName("max_passengers")
var maxPass: String? = null
@SerializedName("driver_revenue")
var priceTrip: String? = null
@SerializedName("origin_coordinate")
var originCoordinate: List<Coordinate>? = null
@SerializedName("destination_coordinate")
var destCoordinate: List<Coordinate>? = null
}
jsonArray
"rows": [
{
"tid": "44551",
"did": null,
"status": 1,
"leaving_time": "1547093186",
"max_passengers": 12,
"total_revenue": 0,
"driver_revenue": 0,
"origin_coordinate": {
"x": 1.43762623,
"y": 103.80153311
},
"destination_coordinate": {
"x": 1.29481854,
"y": 103.78735487
},
"total_requests": 12,
"destination_geom": "0101000020E610000048F0284063F25940854F5F1901BFF43F",
"origin_geom": "0101000020E61000002AB6CC40C7F25940032A19ECF7E4F63F",
"stops": [
{
"sid": "46969",
"count": "4",
"order_seq": 1,
"mode": 0,
"name": "Woodlands Ave 4",
"description": "Blk 532",
"coordinate": {
"x": 1.43059181782,
"y": 103.792699721
},
"eta_time": "1547093186",
"leaving_time": "1547093366"
},