java.lang.Object
{@code JSONArray} has the same type coercion behavior and optional/mandatory accessors as JSONObject. See that class' documentation for details.
Warning: this class represents null in two incompatible ways: the standard Java {@code null} reference, and the sentinel value {@link JSONObject#NULL}. In particular, {@code get} fails if the requested index holds the null reference, but succeeds if it holds {@code JSONObject.NULL}.
Instances of this class are not thread safe. Although this class is nonfinal, it was not designed for inheritance and should not be subclassed. In particular, self-use by overridable methods is not specified. See Effective Java Item 17, "Design and Document or inheritance or else prohibit it" for further information.
Creates a {@code JSONArray} with no values.
public JSONArray()
Creates a new {@code JSONArray} by copying all values from the given collection.
public JSONArray(java.util.Collection copyFrom)
Creates a new {@code JSONArray} with values from the next array in the tokener.
public JSONArray(JSONTokener readFrom)
Creates a new {@code JSONArray} with values from the JSON string.
public JSONArray(String json)
Creates a new {@code JSONArray} with values from the given primitive array.
public JSONArray(Object array)
Returns the number of values in this array.
public int length()
Appends {@code value} to the end of this array.
public org.json.JSONArray put(boolean value)
Appends {@code value} to the end of this array.
public org.json.JSONArray put(double value) throws org.json.JSONException
Appends {@code value} to the end of this array.
public org.json.JSONArray put(int value)
Appends {@code value} to the end of this array.
public org.json.JSONArray put(long value)
Appends {@code value} to the end of this array.
public org.json.JSONArray put(Object value)
Sets the value at {@code index} to {@code value}, null padding this array to the required length if necessary. If a value already exists at {@code index}, it will be replaced.
public org.json.JSONArray put(int index,boolean value) throws org.json.JSONException
Sets the value at {@code index} to {@code value}, null padding this array to the required length if necessary. If a value already exists at {@code index}, it will be replaced.
public org.json.JSONArray put(int index,double value) throws org.json.JSONException
Sets the value at {@code index} to {@code value}, null padding this array to the required length if necessary. If a value already exists at {@code index}, it will be replaced.
public org.json.JSONArray put(int index,int value) throws org.json.JSONException
Sets the value at {@code index} to {@code value}, null padding this array to the required length if necessary. If a value already exists at {@code index}, it will be replaced.
public org.json.JSONArray put(int index,long value) throws org.json.JSONException
Sets the value at {@code index} to {@code value}, null padding this array to the required length if necessary. If a value already exists at {@code index}, it will be replaced.
public org.json.JSONArray put(int index,Object value) throws org.json.JSONException
Returns true if this array has no value at {@code index}, or if its value is the {@code null} reference or {@link JSONObject#NULL}.
public boolean isNull(int index)
Returns the value at {@code index}.
public java.lang.Object get(int index) throws org.json.JSONException
Returns the value at {@code index}, or null if the array has no value at {@code index}.
public java.lang.Object opt(int index)
Removes and returns the value at {@code index}, or null if the array has no value at {@code index}.
public java.lang.Object remove(int index)
Returns the value at {@code index} if it exists and is a boolean or can be coerced to a boolean.
public boolean getBoolean(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is a boolean or can be coerced to a boolean. Returns false otherwise.
public boolean optBoolean(int index)
Returns the value at {@code index} if it exists and is a boolean or can be coerced to a boolean. Returns {@code fallback} otherwise.
public boolean optBoolean(int index,boolean fallback)
Returns the value at {@code index} if it exists and is a double or can be coerced to a double.
public double getDouble(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is a double or can be coerced to a double. Returns {@code NaN} otherwise.
public double optDouble(int index)
Returns the value at {@code index} if it exists and is a double or can be coerced to a double. Returns {@code fallback} otherwise.
public double optDouble(int index,double fallback)
Returns the value at {@code index} if it exists and is an int or can be coerced to an int.
public int getInt(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is an int or can be coerced to an int. Returns 0 otherwise.
public int optInt(int index)
Returns the value at {@code index} if it exists and is an int or can be coerced to an int. Returns {@code fallback} otherwise.
public int optInt(int index,int fallback)
Returns the value at {@code index} if it exists and is a long or can be coerced to a long.
public long getLong(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is a long or can be coerced to a long. Returns 0 otherwise.
public long optLong(int index)
Returns the value at {@code index} if it exists and is a long or can be coerced to a long. Returns {@code fallback} otherwise.
public long optLong(int index,long fallback)
Returns the value at {@code index} if it exists, coercing it if necessary.
public java.lang.String getString(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists, coercing it if necessary. Returns the empty string if no such value exists.
public java.lang.String optString(int index)
Returns the value at {@code index} if it exists, coercing it if necessary. Returns {@code fallback} if no such value exists.
public java.lang.String optString(int index,String fallback)
Returns the value at {@code index} if it exists and is a {@code JSONArray}.
public org.json.JSONArray getJSONArray(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is a {@code JSONArray}. Returns null otherwise.
public org.json.JSONArray optJSONArray(int index)
Returns the value at {@code index} if it exists and is a {@code JSONObject}.
public org.json.JSONObject getJSONObject(int index) throws org.json.JSONException
Returns the value at {@code index} if it exists and is a {@code JSONObject}. Returns null otherwise.
public org.json.JSONObject optJSONObject(int index)
Returns a new object whose values are the values in this array, and whose names are the values in {@code names}. Names and values are paired up by index from 0 through to the shorter array's length. Names that are not strings will be coerced to strings. This method returns null if either array is empty.
public org.json.JSONObject toJSONObject(JSONArray names) throws org.json.JSONException
Returns a new string by alternating this array's values with {@code separator}. This array's string values are quoted and have their special characters escaped. For example, the array containing the strings '12" pizza', 'taco' and 'soda' joined on '+' returns this:
"12\" pizza"+"taco"+"soda"
public java.lang.String join(String separator) throws org.json.JSONException
Encodes this array as a compact JSON string, such as:
[94043,90210]
public java.lang.String toString()
Encodes this array as a human readable JSON string for debugging, such as:
[ 94043, 90210 ]
public java.lang.String toString(int indentSpaces) throws org.json.JSONException
public boolean equals(Object o)
public int hashCode()
From Class | Methods |
---|---|
java.lang.Object | getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize |