Exemplo n.º 1
0
 /**
  * Construct a JSONArray from a Collection.
  *
  * @param collection A Collection.
  */
 public JSONArray(Collection<Object> collection) {
   this.myArrayList = new ArrayList<Object>();
   if (collection != null) {
     Iterator<Object> iter = collection.iterator();
     while (iter.hasNext()) {
       this.myArrayList.add(JSONObject.wrap(iter.next()));
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Construct a JSONArray from an array
  *
  * @throws JSONException If not an array.
  */
 public JSONArray(Object array) throws JSONException {
   this();
   if (array.getClass().isArray()) {
     int length = Array.getLength(array);
     for (int i = 0; i < length; i += 1) {
       this.put(JSONObject.wrap(Array.get(array, i)));
     }
   } else {
     throw new JSONException("JSONArray initial value should be a string or collection or array.");
   }
 }