/** * Visit each JSON Object in the JSON Array. * * @param jsonArray The JSON Array */ protected final void traverseJSONArray(final JSONArray jsonArray) { if (jsonArray == null) { return; } for (int i = 0; i < jsonArray.length(); i++) { if (jsonArray.optJSONObject(i) != null) { this.accept(jsonArray.optJSONObject(i)); } else if (jsonArray.optJSONArray(i) != null) { this.accept(jsonArray.optJSONArray(i)); } } }
/** * Produce a comma delimited text from a JSONArray of JSONObjects using * a provided list of names. The list of names is not included in the * output. * @param names A JSONArray of strings. * @param ja A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ public static String toString(JSONArray names, JSONArray ja) throws JSONException { if (names == null || names.length() == 0) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < ja.length(); i += 1) { JSONObject jo = ja.optJSONObject(i); if (jo != null) { sb.append(rowToString(jo.toJSONArray(names))); } } return sb.toString(); } }
/** * Produce a comma delimited text from a JSONArray of JSONObjects. The * first row will be a list of names obtained by inspecting the first * JSONObject. * @param ja A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ public static String toString(JSONArray ja) throws JSONException { JSONObject jo = ja.optJSONObject(0); if (jo != null) { JSONArray names = jo.names(); if (names != null) { return rowToString(names) + toString(names, ja); } } return null; }
JSONObject objVal = a.optJSONObject(i); if (objVal != null) { this.writeObject(objVal);