tags:

views:

324

answers:

2

Is there a way to convert JSON Array to normal Java Array for android ListView data binding?

A: 
ArrayList<String> list = new ArrayList<String>();     
JSONArray jsonArray = (JSONArray)jsonObject; 
if (jsonArray != null) { 
   for (int i=0;i<jsonArray.size();i++){ 
    list.add(jsonArray.get(i).toString()); 
} 
Pentium10
+2  A: 

If you don't already have a JSONArray object, call

JSONArray jsonArray = new JSONArray(jsonArrayString);

Then simply loop through that, building your own array. This code assumes it's an array of strings, it shouldn't be hard to modify to suit your particular array structure.

List<String> list = new ArrayList<String>();
for (int i=0; i<jsonArray.size(); i++) {
    list.add( jsonArray.getString(i) );
}
Nick