I am trying to parse JSON in kotlin where I have a suspend function returning a list but it is giving an error io.ktor.serialization.JsonConvertException: Illegal input
. The function is as follows
private suspend fun fetchMenu(): List<MenuItems> {
return httpClient.
get("https://raw.githubusercontent.com/Meta-Mobile-Developer-PC/Working-With-Data-API/main/littleLemonSimpleMenu.json")
.body()
}
It shows the error is in body
line.
The MenuItems
class is
@Serializable
data class MenuItems(
val id: Int,
val title: String,
val price: Int
) {
fun toMenuItemRoom() = MenuItemRoom(
id,title,price.toDouble()
)
}
How can I parse it to avoid the error?