0

改造 2.6。

 @GET("/event")
    suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Event>>

在役:

import retrofit2.Response

 suspend fun getEvents(
            orgn: Int,
            event: Int,
            isCustomtHandle: Boolean = false
        ): Response<*> {
           return waitressCallRestClient.getEvents(orgn, event)
        }

在我的 ViewModel 中:

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope

 viewModelScope.launch(Dispatchers.Main) {
            val response = TransportService.getEvents(100, 200)
            if (response.isSuccessful) { 
                val eventList: List<Event> = response.body() as List<Event>

如您所见,我必须转换为List<Event> 是否可以避免手动转换?

4

1 回答 1

0

像这样使用Any

@GET("/event")
suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Any>>

然后

val eventList: List<Any> = response.body() 
于 2019-11-10T03:06:24.980 回答