androidkotlincallbackrx-java2

Expected begin_array but was begin_object at line 1 column 2 path $ on Kotlin+Android


I called the PetFinder API to get data. When I wanted to show the data on screen I got this error. I used Call sequence to get data and I used enqueue on the ViewModel.

I tried to use fromJson() method but the code gave me error


Solution

  • SOLUTION:

    My data class was

    data class Animal(
    @SerializedName("name")
    val name:String,
    @SerializedName("age")
    val age: String,
    @SerializedName("gender")
    val gender:String,
    )
    

    and I used Animal when I use enqueue method. I created another data class :

    data class Deneme(
        val animals: List<Animal>,
    )
    

    and I used Deneme class instead of Animal

        repository.getData().enqueue(object : Callback<Deneme> {