I saw the Java source code for JSONObject, and the difference between accumulate and put is that with accumulation (String key, Object Value), if there is a specific value for the "key", then the object is checked for an array, if it is an array, then "value" is added to the array; otherwise, an array is created for this.
In the case, however, the key, if it exists, its value is replaced by the value - "value"
Here is the source of the accumulation of JSONObject (String key, Object Value)
public JSONObject accumulate(String name, Object value) throws JSONException { Object current = nameValuePairs.get(checkName(name)); if (current == null) { return put(name, value); } if (current instanceof JSONArray) { JSONArray array = (JSONArray) current; array.checkedPut(value); } else { JSONArray array = new JSONArray(); array.checkedPut(current); array.checkedPut(value); nameValuePairs.put(name, array); } return this; }
And here is the code for JSONObject put (String key, Object value)
public JSONObject put(String name, boolean value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
source share