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
(String key, Object value)
| 729 | * the key is not a JSONArray. |
| 730 | */ |
| 731 | public JSONObject append(String key, Object value) throws JSONException { |
| 732 | testValidity(value); |
| 733 | Object object = this.opt(key); |
| 734 | if (object == null) { |
| 735 | this.put(key, new JSONArray().put(value)); |
| 736 | } else if (object instanceof JSONArray) { |
| 737 | this.put(key, ((JSONArray) object).put(value)); |
| 738 | } else { |
| 739 | throw new JSONException("JSONObject[" + key + "] is not a JSONArray."); |
| 740 | } |
| 741 | return this; |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Get the value object associated with a key. |
no test coverage detected