使用 Klaxon 在 Kotlin 中解析包含嵌套列表的 JSON
Parse JSON containing nested lists in Kotlin with Klaxon
我是 Kotlin 新手,正在尝试解析 JSON 中的列表列表:
data class Root (val lists: List<List<String>>)
val result = Klaxon().parse<Root>("""
{
"lists": [["red", "green", "blue"]]
}
""")
但是我得到这个运行时异常:
Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
Klaxon 好像不太明白List<List<String>>
.
我还需要它来对嵌套集合进行一般性工作:
List<List<*>>
Map<String, List<*>>
List<Map<String, *>>
Map<String, Map<String, *>>
这已在 Klaxon 2.1.11 中修复。
我是 Kotlin 新手,正在尝试解析 JSON 中的列表列表:
data class Root (val lists: List<List<String>>)
val result = Klaxon().parse<Root>("""
{
"lists": [["red", "green", "blue"]]
}
""")
但是我得到这个运行时异常:
Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
Klaxon 好像不太明白List<List<String>>
.
我还需要它来对嵌套集合进行一般性工作:
List<List<*>>
Map<String, List<*>>
List<Map<String, *>>
Map<String, Map<String, *>>
这已在 Klaxon 2.1.11 中修复。