0

i have a json like this:

{"code":200,"msg":"111",data:[{"name":"va","list":[{"code":"11"}]},{"name":"va","list":[{"code":"11"}]}]}

my class like this:

@Serializable
class ServerResponse<T> {
    @SerialName(value = "code")
    var code = 0

    @SerialName(value = "msg")
    var msg: String? = null

    @SerialName(value = "data")
    var data: T? = null
        private set
}

@Serializable
data class PluginInfo(
    @SerialName(value = "name")
    val name: String,
    @SerialName(value = "list")
    val list: MutableList<PluginConfig>
)

@Serializable
data class PluginConfig(
    @SerialName(value = "code")
    val code: String
)

when i use JSON.decodeFromString:

val response =
                json.decodeFromString<ServerResponse<MutableList<PluginInfo>>>(pluginInfoJson)

this throw exception:

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 271: Expected quotation mark '"', but had '1' instead at path: $.data[0].

Gary
  • 13
  • 4

0 Answers0