convert ArrayList to JSONArray

If I read the JSONArray constructors correctly, you can build them from any Collection (arrayList is a subclass of Collection) like so:

ArrayList<String> list = new ArrayList<String>();
list.add("foo");
list.add("baar");
JSONArray jsArray = new JSONArray(list);

References:

  • jsonarray constructor:
    http://developer.android.com/reference/org/json/JSONArray.html#JSONArray%28java.util.Collection%29
  • collection:
    http://developer.android.com/reference/java/util/Collection.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)