/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param value a Map value * @return this */ public JSONArray put(Map<?, ?> value) { put(new JSONObject(value)); return this; }
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names.<p> * * @param string The comma delimited text * @return A JSONArray of JSONObjects * @throws JSONException if something goes wrong */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection.<p> * * @param key a key string * @param value a Collection value * @return this * @throws JSONException if something goes wrong */ public JSONObject put(String key, Collection<Object> value) throws JSONException { put(key, new JSONArray(value)); return this; }
/** * Get the value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws JSONException if the key is not found */ public Object get(String key) throws JSONException { Object o = opt(key); if (o == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); } return o; }
/** * Append an object value.<p> * * @param o the object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method * @return this * @throws JSONException if the value is out of sequence */ public JSONWriter value(Object o) throws JSONException { return append(JSONObject.valueToString(o)); }
/** * Get the JSONArray associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONArray value * @throws JSONException if there is no value for the index or if the value is not a JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { Object o = get(index); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); }
/** * Get the object value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return an object value * @throws JSONException if there is no value for the index */ public Object get(int index) throws JSONException { Object o = opt(index); if (o == null) { throw new JSONException("JSONArray[" + index + "] not found."); } return o; }
/** * Construct a JSONArray from a source JSON text.<p> * * @param source a string that begins with * <code>[</code> <small>(left bracket)</small> * and ends with <code>]</code> <small>(right bracket)</small> * @throws JSONException if there is a syntax error */ public JSONArray(String source) throws JSONException { this(new JSONTokener(source)); }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param value a Map value * @return this */ public JSONArray put(Map value) { put(new JSONObject(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection.<p> * * @param key a key string * @param value a Collection value * @return this * @throws JSONException if something goes wrong */ public JSONObject put(String key, Collection value) throws JSONException { put(key, new JSONArray(value)); return this; }
/** * Get the value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws JSONException if the key is not found */ public Object get(String key) throws JSONException { Object o = opt(key); if (o == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); } return o; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names.<p> * * @param names A JSONArray of strings. * @param string The comma delimited text * @return A JSONArray of JSONObjects * @throws JSONException if something goes wrong */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * Append an object value.<p> * * @param o the object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method * @return this * @throws JSONException if the value is out of sequence */ public JSONWriter value(Object o) throws JSONException { return this.append(JSONObject.valueToString(o)); }
/** * Get the JSONObject associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONObject value * @throws JSONException if there is no value for the index or if the value is not a JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { Object o = get(index); if (o instanceof JSONObject) { return (JSONObject)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param index the index must be between 0 and length() - 1 * @param value the Map value * @return this * @throws JSONException if the index is negative or if the the value is * an invalid number */ public JSONArray put(int index, Map<?, ?> value) throws JSONException { put(index, new JSONObject(value)); return this; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names.<p> * * @param names A JSONArray of strings. * @param string The comma delimited text * @return A JSONArray of JSONObjects * @throws JSONException if something goes wrong */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names.<p> * * @param string The comma delimited text * @return A JSONArray of JSONObjects * @throws JSONException if something goes wrong */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }