Home > Software engineering >  Parse Json to Map<String,String> kotlin multiplatform
Parse Json to Map<String,String> kotlin multiplatform

Time:03-30

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>

CodePudding user response:

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.

  • Related