0

How do I convert from JSON array objects to Kotlin?

Format from JSON to Kotlin


 "company": {
54: {
"id": "54",
"type": "metan",
"region_name": "Urganch shahri",
"open_close": 1,
"name": "Xorazm IDEAL GAZ",
"image": "https://metan.mbos.uz/persons/145787891644148634.jpg",
"start_time": "00:00",
"end_time": "23:59",
"price": "2600",
"orientr": "Obl.GAI ko'prik o'ng tomonida",
"googlemap": "https://maps.google.com/maps?q=41.530320,60.649560&ll=41.530320,60.649560&z=16"
},
56: {
"id": "56",
"type": "metan",
"region_name": "Xonqa tumani",
"open_close": 1,
"name": "Shaxzodbek Sulaymon",
"image": "https://metan.mbos.uz/persons/5634558381644152414.jpg",
"start_time": "00:00",
"end_time": "23:59",
"price": "2500",
"orientr": "Oxunbabayev. ShoxOil",
"googlemap": "https://maps.google.com/maps?q=41.491009,60.748586&ll=41.491009,60.748586&z=16"
},..57..58..59..60

  1. The main problem is object would be an increase

please give me a solution or link where I will found solution

3
  • Can you post what you have tried to do this? Commented Jun 19, 2022 at 3:58
  • I have tried to do it with Map Interface but it's not working, I have used JSON Kotlin Formatter Plugin but it's actually not working it was statically working, but I want this, I want it is dynamic Commented Jun 19, 2022 at 4:39
  • Post Your map interface code here Commented Jun 19, 2022 at 4:45

1 Answer 1

2

You can use "JSON To Kotlin Class ​(JsonToKotlinClass)​" plugin for Android Studio. This plugin coverts existed JSON to data classes.

How use this plugin you can find here.

How add plugin to your Android studio you can find here.

Sign up to request clarification or add additional context in comments.

2 Comments

Please see the main problem below
Create a model class for the inner object like in 54, 56, After that get value in hashmap which has key (Int) and value (Inner object model).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.