Answers for "how to create map from json kotlin"

1

how to create map in kotlin

fun main(args: Array<String>){  
  
    val myMap = mapOf<Int,String>(1 to "Ajay", 4 to "Vijay", 3 to "Prakash")  
    for(key in myMap.keys){  
        println(myMap[key])  
    }  
}
Posted by: Guest on November-10-2021
2

make map kotlin

val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
Posted by: Guest on September-14-2020
-1

json to map kotlin

fun JSONObject.toMap(): Map<String, *> = keys().asSequence().associateWith {
    when (val value = this[it])
    {
        is JSONArray ->
        {
            val map = (0 until value.length()).associate { Pair(it.toString(), value[it]) }
            JSONObject(map).toMap().values.toList()
        }
        is JSONObject -> value.toMap()
        JSONObject.NULL -> null
        else            -> value
    }
}
Posted by: Guest on October-29-2021

Browse Popular Code Answers by Language