Skip to content
Advertisement

Handle Response Kotlin Retrofit

I’m new to Kotlin and android development. Have been struggling to get my retrofit api to work.
But have found a way to do it after some search on SO. I get the data response now, but I don’t know how to “separate” it, so that i can work around with it.

this is my json response:

JavaScript

and my model class

JavaScript

and finally my get data function

JavaScript

I get the response, but I don’t know how to unfold the data, so that I can for example add all country names to an ArrayList.

I have tried doing this without the class Countrys, using <List> or Arraylist but i get the error on my response:

E/dadosApiError: erro no retorno Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

JavaScript

I have also tried previously with List

Advertisement

Answer

you will need to change Countrys class into a data class and add the SerializedName data for the object countrys like this

JavaScript

then you can access your data by using this

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement