array.checkedPut(value); } else { JSONArray array = new JSONArray(); array.checkedPut(current); array.checkedPut(value); nameValuePairs.put(name, array);
array.checkedPut(value); } else { JSONArray array = new JSONArray(); array.checkedPut(current); array.checkedPut(value); nameValuePairs.put(name, array);
/** * Appends values to the array mapped to {@code name}. A new {@link JSONArray} * mapping for {@code name} will be inserted if no mapping exists. If the existing * mapping for {@code name} is not a {@link JSONArray}, a {@link RuntimeException} * will be thrown. * * @param name The name of the array to which the value should be appended. * @param value The value to append. * @return this object. * @throws RuntimeException if {@code name} is {@code null} or if the mapping for * {@code name} is non-null and is not a {@link JSONArray}. */ public JSONObject append(String name, Object value) { testValidity(value); Object current = nameValuePairs.get(checkName(name)); final JSONArray array; if (current instanceof JSONArray) { array = (JSONArray) current; } else if (current == null) { JSONArray newArray = new JSONArray(); nameValuePairs.put(name, newArray); array = newArray; } else { throw new RuntimeException("JSONObject[\"" + name + "\"] is not a JSONArray."); } array.checkedPut(value); return this; }
/** * Appends values to the array mapped to {@code name}. A new {@link JSONArray} * mapping for {@code name} will be inserted if no mapping exists. If the existing * mapping for {@code name} is not a {@link JSONArray}, a {@link RuntimeException} * will be thrown. * * @param name The name of the array to which the value should be appended. * @param value The value to append. * @return this object. * @throws RuntimeException if {@code name} is {@code null} or if the mapping for * {@code name} is non-null and is not a {@link JSONArray}. */ public JSONObject append(String name, Object value) { testValidity(value); Object current = nameValuePairs.get(checkName(name)); final JSONArray array; if (current instanceof JSONArray) { array = (JSONArray) current; } else if (current == null) { JSONArray newArray = new JSONArray(); nameValuePairs.put(name, newArray); array = newArray; } else { throw new RuntimeException("JSONObject[\"" + name + "\"] is not a JSONArray."); } array.checkedPut(value); return this; }