Hello, i'm getting the following error, can't unde...
# ktor
r
Hello, i'm getting the following error, can't understand why Illegal input: Unexpected JSON token at offset 0: Expected start of the object '{', but had '[' instead at path: $ Ktor client is getting the data BODY START 165235.346 I [{"id":22,"title":"Sleek Wireless Computer Mouse","slug":"sleek-wireless-computer-mouse","price":10,"description":"Experience smooth and precise navigation with this modern wireless mouse, featuring a glossy finish and a comfortable ergonomic design. Its responsive tracking and easy-to-use interface make it the perfect accessory for any desktop or laptop setup. The stylish blue hue adds a splash of color to your workspace, while its compact size ensures it fits neatly in your bag for on-the-go productivity.","category":{"id":2,"name":"nuevo","slug":"nuevo","image":"

https://i.imgur.com/ZANVnHE.jpeg

","creationAt":"2025-03-21T111847.000Z","updatedAt":"2025-03-21T153209.000Z"},"images":["

https://i.imgur.com/w3Y8NwQ.jpeg

","

https://i.imgur.com/WJFOGIC.jpeg

","

https://i.imgur.com/dV4Nklf.jpeg

"],"creationAt":"2025-03-21T111847.000Z","updatedAt":"2025-03-21T111847.000Z"}] 165235.346 I BODY END 165235.347 I httpResponse: HttpResponse[https://api.escuelajs.co/api/v1/products?offset=0&limit=1, 200 OK] 165235.352 I RESPONSE https://api.escuelajs.co/api/v1/products?offset=0&limit=1 failed with exception: io.ktor.serialization.JsonConvertException: Illegal input: Unexpected JSON token at offset 0: Expected start of the object '{', but had '[' instead at path: $ 165235.352 I JSON input: [{"id":22,"title":"Sleek Wirel..... 165235.353 I Illegal input: Unexpected JSON token at offset 0: Expected start of the object '{', but had '[' instead at path: But unable to deserialise the data
Copy code
data class ProductApiItem(
    @SerialName("id")
    val id: Int? = null,
    @SerialName("title")
    val title: String? = null,
    @SerialName("slug")
    val slug: String? = null,
    @SerialName("price")
    val price: Int? = null,
    @SerialName("description")
    val description: String? = null,
    @SerialName("category")
    val category: Category? = null,
    @SerialName("images")
    val images: List<String?>? = null,
    @SerialName("creationAt")
    val creationAt: String? = null,
    @SerialName("updatedAt")
    val updatedAt: String? = null
)

fun ProductApiItem.toProductItem(): ProductItem? {
    return if (id != null)
        ProductItem(
            id = id.toLong(),
            title = title ?: "",
            slug = slug ?: "",
            price = price?.toLong() ?: 0,
            description = description ?: "",
            categoryId = category?.id?.toLong() ?: 0,
            images = images?.mapNotNull { it } ?: emptyList()
        )
    else
        null
}

@Serializable
data class ProductListApiResponse(
    val products: List<ProductApiItem>,
)

What i'm doing wrong? thanks
c
Please don’t cross post. Answers are lost and hard to follow for others.
r
ok sorry @Chrimaeon