Skip to content
Advertisement

how to display categories in data class with retrofit2 – Kotlin

i am trying to display data from API using retrofit2 in koltin

but the API shows that there is categoryId before the data i am calling as showing below:

JavaScript

i tried to call only (eventName, eventPhoto, eventLink) in my data class as showing below:

JavaScript

API interface:

JavaScript

Adapter:

JavaScript

after i run the application, it shows that the data are null

do i need to call “categoryId”?

and if yes, how can i call 2 arrays in the same data class?

the Adapter and the code in my activity is correct because i tested it with another API

so what am i doing wrong here?

——————————- Solution ————————

refer to the answer down and i have to change how i call the data from the adapter

instead of this:

JavaScript

do this:

JavaScript

Advertisement

Answer

Check point

  • data that you want is in List of List
    • jsonArray > jsonArray > IimfinderDataJson IimfinderData by List
  • eventPhoto is Object, not String

try this code

Call<List<IimfinderData>> -> Call<List<IlmFinders>>

JavaScript

and

JavaScript

if your data class properties name is same with json element, you don’t need @SerializedName

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