Ayden
07/18/2018, 12:52 PM{
"status": true,
"code": null,
"result": {
"id": 1,
"name": "User",
"email": "<mailto:user@gmail.com|user@gmail.com>",
"created_at": "2018-07-12 15:25:42",
"updated_at": "2018-07-12 15:25:42"
}
}
This is my data class.
data class Response (
@Json(name = "status") val status: Boolean?,
@Json(name = "code") val code: Int?,
@Json(name = "result") val result: UserResult?
)
data class UserResult (
@Json(name = "id") val id: Int?,
@Json(name = "name") val name: String?,
@Json(name = "email") val email: String?
)
This is my Retrofit call.enqueue
call.enqueue(object : Callback<Response> {
override fun onFailure(call: Call<Response>?, t: Throwable?) {
...
}
override fun onResponse(call: Call<Response>?, response: Response<Response>) {
if (response.isSuccessful) {
val result = response.body()?.result.toString()
// The result being return is id=1, name=Username, email=username@email.com according to Log.d
// How to extract the user information
}
}
})
May I know how to extract the user information from the response given?
I have try Moshi Custom Type Adapter
and various of method.
But I would either get Conversation error
or wrong result.
PS: I am double posting this on different channel because I don't know which channel is appropriate to ask this