I’m unsuccessfully trying to find a way to iterate over a Json object (which is expected to only contain properties with String values) so that I can fill a Map<String,String> from it. In either way I end up with an illegal cast exception.
private fun jsonToMap(json: Json): Map<String, String> {
val map: MutableMap<String, String> = linkedMapOf()
for (key in json) {
map.put(key, json[key] as String)
}
// or
for( (name, value) in json ) {
map.put(name, value as String)
}
return map
}
val jsObject = js("Object")
private fun parse(json: dynamic): Map<String, Transaction> {
val entries= jsObject.entries(json) as Array<Array<dynamic>>
return entries
.map { entry ->
entry[0] as String to parseObject(entry[1])
}.toMap()
}
where in your case the parseObject method would be
private fun parseObject(json:dynamic) = json as String