0

I have Json:

{
  "216632": {
    "prefiks": "",
    "anyid": "0",
    "tel": "123456789",
    "firma": "Brand",
    "fio": "Name",
    "comment": "Text",
    "address": "Address",
    "kv": "99",
    "adres_id": "11130",
    "gps": "99.666666 66.777777",
    "oplata": 0,
    "tovarName": "Simple.",
    "tovar": "23",
    "fish": "0",
    "finish": "1",
    "utro": "0",
    "unik": "0",
    "chek": "0",
    "bezcont": "0",
    "courier_price": "0",
    "sort": "13"
  },
  "246578":{
......
......
......

the key 216322 can have absolutely any name (215423,654345...) how do I serialize it in a data class? I have:

@kotlinx.serialization.Serializable
data class ServerData(
    val **UUID** : FromServer
)
@kotlinx.serialization.Serializable
data class FromServer(
    val adres: String,
    val adres_id: String,
    val anyid: String,
    val bezcont: String,
    val chek: String,
    val comment: String,
    val courier_price: String,
    val finish: String,
    val fio: String,
    val firma: String,
    val fish: String,
    val kv: String,
    val oplata: Int,
    val prefiks: String,
    val sort: String,
    val tel: String,
    val tovar: String,
    val unik: String,
    val utro: String
)

UUID is naturally the wrong option, how do I do it right? what should be instead of UUID

I use KotlinX Serialization

I can't find the information anywhere

1 Answers1

0

You may have to parse it in 2 steps: First, parse your entire Json-String as a JsonObject. Then you can query all its attributes, then parse each of them for your FromServer.

Another way, if you use Gson or Moshi, you can write a customize adapter for these sort of json

fshdn19
  • 374
  • 1
  • 8