0

I am learning to use apis in android and I am trying to get a list of images from the Dog Ceo api.

I am using the kotlin serialization, coil and retrofit library.

The Json response looks like this (Note: I've shortened the list because it's so long.)

{
    "message": [
        "https://images.dog.ceo/breeds/hound-afghan/n02088094_1003.jpg",
        "https://images.dog.ceo/breeds/hound-afghan/n02088094_10263.jpg",
        "https://images.dog.ceo/breeds/hound-afghan/n02088094_10715.jpg"
    ],
    "status": "success"
}

My model.

@Serializable
data class Dog(
    @SerialName("message")
    val image: List<String>,
    @SerialName("status")
    val status: String
)

My interface with an @GET annotation and the endpoint to get the images with a specific breed.

interface DogsApi {
    @GET("hound/images")
    suspend fun dogApi(): List<Dog>
}

But when running the app I get the following error.

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.dogimages, PID: 8887
    kotlinx.serialization.json.internal.JsonDecodingException: Expected start of the array '[', but had 'EOF' instead at path: $
    JSON input: .....reeds\/hound-walker\/n02089867_953.jpg"],"status":"success"}

Sorry for the inconvenience, any help is appreciated!

I have tried manipulating the url with @Query or @Path but the result is the same.

  • That error makes me think that perhaps the JSON response is not valid, or somehow not getting parsed correctly. Have you verified the integrity of the JSON response itself? It's hard to tell much else without seeing more code with your setup / calling of the API. But since you're new to APIs, in case you aren't aware, the EOF refers to End of File, and where it's expecting to see the array of dogs, it's getting an end of file. I'd look into the response JSON itself, as well as how you're parsing the JSON. – Jüri Kiin Mar 13 '23 at 17:50
  • Hello ! Thank you very much for answering ! Honestly I don't have much idea how to verify the integrity of the JSON response I have to do research on the subject. If you want to see more code I can give you the link with the repository on github. – Maxi Pelizzoni Mar 13 '23 at 18:21
  • You can put it through https://jsonlint.com/ it should help validate the formatting of your JSON. – Jüri Kiin Mar 29 '23 at 14:10

0 Answers0