/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. */ public JSONObject toJSONObject(JSONArray names) { if (names == null || names.Length == 0 || length() == 0) return null; JSONObject jo = new JSONObject(); for (int i = 0; i < names.Length; i += 1) { jo.put(names.getString(i), opt(i)); } return jo; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. */ public JSONArray toJSONArray(JSONArray names) { if (names == null || names.Length == 0) return null; JSONArray ja = new JSONArray(); for (int i = 0; i < names.Length; i += 1) { ja.put(opt(names.getString(i))); } return ja; }