There is an ArrayList<Integer> array = new ArrayList<Integer>() ,

I translate it into Json with the command: new Gson().toJson(array)

How to parse Json back into an array?

  • one
    Gson.fromJSON(...) logically ... tried? - Vladyslav Matviienko
  • fromJSON for some reason, the parsit is not as an Integer, but as a Double, and crashes with ClassCastException - Alexey

2 answers 2

 Type listType = new TypeToken<List<Integer>>() {}.getType(); List<Integer> result = new Gson().fromJson(json, listType); 
     ArrayList<String> listdata = new ArrayList<String>(); JSONArray jArray = (JSONArray)jsonObject; if (jArray != null) { for (int i=0;i<jArray.length();i++){ listdata.add(jArray.get(i).toString()); } } 

    a source