Parse Json to Map<String,String> kotlin multiplatform
Asked Answered
P

1

6

My resialized is "{"2":"Hello","Tesst":"Value"}"

I tried to parse this string to Map<String,String>

            val resialized = readFile(createStorageDirectoryPath(getManifestFilePath()), MANIFEST_FILE_NAME, errorOut)
                manifest = Json.decodeFromString(/*serializer*/, resialized)

How I create a serializer for Map<String,String>

Pontone answered 30/3, 2022 at 9:46 Comment(0)
H
11

You can use an other version of decodeFromString which will take care of deserializer by itself.

import kotlinx.serialization.decodeFromString

val res = Json.decodeFromString<Map<String, String>>("{\"2\":\"Hello\",\"Tesst\":\"Value\"}")

It's marked with ExperimentalSerializationApi, but I had no problems using it for the last year. This method is recommended by documentation.

Haploid answered 30/3, 2022 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.