0

I have the following json, how can i convert it to arrayList?

"data": [{
            "label": "Venezuela",
            "value": "290"
        }, {
            "label": "Saudi",
            "value": "260"
        }, {
            "label": "Canada",
            "value": "180"
        }, {
            "label": "Iran",
            "value": "140"
        }, {
            "label": "Russia",
            "value": "115"
        }, {
            "label": "UAE",
            "value": "100"
        }, {
            "label": "US",
            "value": "30"
        }, {
            "label": "China",
            "value": "30"
        }]
    }
Phil Ross
  • 25,590
  • 9
  • 67
  • 77
tarun kumar143
  • 391
  • 4
  • 7
  • 1
    Look here: https://stackoverflow.com/questions/39999420/convert-json-to-object-list or here : https://stackoverflow.com/questions/443499/convert-json-to-map – jschnasse Oct 15 '18 at 09:41

1 Answers1

0

You need to convert it manually iterate each json and assign it to an object then you can add it to a collection. or even you can use Gson Library take a look at the following, gson can map your attribute into Java Object.

JsonElement yourJson = mapping.get("data");
Type listType = new TypeToken<List<YourModel>>() {}.getType(); //YourModel should contains the same attributes which the json have (Exactly)

List<String> yourList = new Gson().fromJson(yourJson, listType);
Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34