Fedora
01/18/2022, 4:08 PM[
{
"type" : "food",
"value" : "pizza, buger, pasta"
},
{
"type" : "drink",
"value" : "soda, Mountain Dew, redbull"
}
]
Chrimaeon
01/18/2022, 4:13 PMdata class MyValues(val type: String, val value: String)
and then create a list like
val mylist = listOf(
MyValues("food", "pizza, burger, pasta"),
MyValues("drink", "soda, Mountain Dew, redbull"
)
Fedora
01/18/2022, 4:16 PMmutableMapOf
and Pair
etc!Casey Brooks
01/18/2022, 4:25 PMFedora
01/18/2022, 4:27 PMFedora
01/18/2022, 4:28 PMFedora
01/18/2022, 4:30 PMval myData = mutableMapOf<String, String>().apply {
Pair(blah, blah)
}but the output wasnt what i needed
Casey Brooks
01/18/2022, 4:33 PMlistOf(
mapOf(
"type" to "food",
"value" to "pizza, burger, pasta",
),
mapOf(
"type" to "drink",
"value" to "soda, Mountain Dew, redbull",
),
)
Generally-speaking, a JSON string can be manually converted to ad-hoc Kotlin code by replacing []
with listOf()
, {}
with mapOf()
, and :
with to
. It's almost always better to use actual objects for type-safety, but this is an optiongildor
01/18/2022, 4:33 PMgildor
01/18/2022, 4:34 PMgildor
01/18/2022, 4:38 PM