📜  json 映射 kotlin - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:01.510000             🧑  作者: Mango

代码示例1
fun JSONObject.toMap(): Map = 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
    }
}