Code example for Map

Methods: get, put, remove

0
     *     infinities}. 
     * @return this object. 
     */ 
    public JSONObject put(String name, Object value) throws JSONException {
        if (value == null) {
            nameValuePairs.remove(name);
            return this;
        } 
        if (value instanceof Number) {
            // deviate from the original by checking all Numbers, not just floats & doubles 
            JSON.checkDouble(((Number) value).doubleValue());
        } 
        nameValuePairs.put(checkName(name), value);
        return this;
    } 
 
    /** 
     * Equivalent to {@code put(name, value)} when both parameters are non-null; 
     * does nothing otherwise. 
     */ 
    public JSONObject putOpt(String name, Object value) throws JSONException {
        if (name == null || value == null) {
            return this;
        } 
        return put(name, value);
    } 
 
    /** 
     * Appends {@code value} to the array already mapped to {@code name}. If 
     * this object has no mapping for {@code name}, this inserts a new mapping. 
     * If the mapping exists but its value is not an array, the existing 
     * and new values are inserted in order into a new array which is itself 
     * mapped to {@code name}. In aggregate, this allows values to be added to a 
     * mapping one at a time. 
     * 
     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, 
     *     Integer, Long, Double, {@link #NULL} or null. May not be {@link 
     *     Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. 
     */ 
    public JSONObject accumulate(String name, Object value) throws JSONException {
        Object current = nameValuePairs.get(checkName(name));
        if (current == null) {
            return put(name, value);
        } 
 
        // check in accumulate, since array.put(Object) doesn't do any checking 
        if (value instanceof Number) {
            JSON.checkDouble(((Number) value).doubleValue());
        } 
 
        if (current instanceof JSONArray) {
            JSONArray array = (JSONArray) current;
            array.put(value);
        } else { 
            JSONArray array = new JSONArray();
            array.put(current);
            array.put(value);
            nameValuePairs.put(name, array);
        } 
        return this;
    } 
 
    String checkName(String name) throws JSONException {