Append values to the array under a key. If the key does not exist in the JSONObject, then the key is put in the JSONObject with its value being a JSONArray containing the value parameter. If the key was already associated with a JSONArray, then the value parameter is appended to it. @param key A k
(String key, Object value)
| 396 | * associated with the key is not a JSONArray. |
| 397 | */ |
| 398 | public JSONObject append(String key, Object value) throws JSONException { |
| 399 | testValidity(value); |
| 400 | Object object = opt(key); |
| 401 | if (object == null) { |
| 402 | put(key, new JSONArray().put(value)); |
| 403 | } else if (object instanceof JSONArray) { |
| 404 | put(key, ((JSONArray)object).put(value)); |
| 405 | } else { |
| 406 | throw new JSONException("JSONObject[" + key + |
| 407 | "] is not a JSONArray."); |
| 408 | } |
| 409 | return this; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | /** |
no test coverage detected