0

I got dynamic number of key in json object it will be change according to data i am using retrofit

JSON

{
"response_message": "Settings has been displayed successfully",
"deliveryCharges": [
  {
    "iSettingId": 2,
    "vSettingDescription": "deliveryCharges",
    "vSettingName1": 1,
    "vSettingName2": 1.5,
    "vSettingName3": 1.75,
    .
    .
    .
    "vSettingNamen": 1.75
  },
  {
    "iSettingId": 3,
    "vSettingDescription": "deliveryCharges",
    "vSettingName1": 1,
    "vSettingName2": 1.5,
    "vSettingName3": 1.75,
    .
    .
    .
    "vSettingNamen": 1.75
  },
  {
    "iSettingId": 4,
    "vSettingDescription": "deliveryCharges",
    "vSettingName1": 1,
    "vSettingName2": 1.5,
    "vSettingName3": 1.75,
    .
    .
    .
    "vSettingNamen": 1.75
  }
]
}

here i can get n number of vSettingName. It is totally dynamic so how can i make POJO for this

Community
  • 1
  • 1
Manthan Patel
  • 993
  • 1
  • 9
  • 20

1 Answers1

1

Try with this

Gson gson = new Gson();
Type mapType = new TypeToken<List<Map<String, String>>>(){}.getType(); //define generic type
List<Map<String, String>> result = gson.fromJson(deliveryCharges,mapType);
Melebius
  • 6,183
  • 4
  • 39
  • 52
Shweta Nandha
  • 728
  • 1
  • 8
  • 19