/** * Construct a JSONArray from an array with a bean. The array should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(Object array, boolean includeSuperClass) throws JSONException { this(); if (array.getClass().isArray()) { int length = Array.getLength(array); for (int i = 0; i < length; i += 1) { Object o = Array.get(array, i); if (JSONObject.isStandardProperty(o.getClass())) { this.myArrayList.add(o); } else { this.myArrayList.add(new JSONObject(o, includeSuperClass)); } } } else { throw new JSONException("JSONArray initial value should be a string or collection or array."); } }
/** * Construct a JSONArray from a collection of beans. The collection should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(Collection collection, boolean includeSuperClass) { this.myArrayList = new ArrayList(); if (collection != null) { Iterator iter = collection.iterator(); ; while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map) { this.myArrayList.add(new JSONObject((Map) o, includeSuperClass)); } else if (!JSONObject.isStandardProperty(o.getClass())) { this.myArrayList.add(new JSONObject(o, includeSuperClass)); } else { this.myArrayList.add(o); } } } }
/** * Construct a JSONArray from a collection of beans. The collection should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(final Collection collection, final boolean includeSuperClass) { myArrayList = collection == null ? new ArrayList<Object>() : new ArrayList<Object>(collection.size()); if (collection != null) { Iterator<Object> iter = collection.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map<?, ?>) { myArrayList.add(new JSONObject((Map<?, ?>) o, includeSuperClass)); } else if (!JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(new JSONObject(o, includeSuperClass)); } else { myArrayList.add(o); } } } }