java.lang.Object | |
↳ | org.json.JSONArray |
A dense indexed sequence of values. Values may be any mix of
JSONObjects
, other JSONArrays
, Strings,
Booleans, Integers, Longs, Doubles, null
or NULL
.
Values may not be NaNs
, infinities
, or of any type not listed here.
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 null
reference, and the sentinel value NULL
. In particular, get
fails if the requested index
holds the null reference, but succeeds if it holds 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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a
JSONArray with no values. | |||||||||||
Creates a new
JSONArray by copying all values from the given
collection. | |||||||||||
Creates a new
JSONArray with values from the next array in the
tokener. | |||||||||||
Creates a new
JSONArray with values from the JSON string. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares this instance with the specified object and indicates if they
are equal.
| |||||||||||
Returns the value at
index . | |||||||||||
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. | |||||||||||
Returns the value at
index if it exists and is a double or can
be coerced to a double. | |||||||||||
Returns the value at
index if it exists and is an int or
can be coerced to an int. | |||||||||||
Returns the value at
index if it exists and is a JSONArray . | |||||||||||
Returns the value at
index if it exists and is a JSONObject . | |||||||||||
Returns the value at
index if it exists and is a long or
can be coerced to a long. | |||||||||||
Returns the value at
index if it exists, coercing it if
necessary. | |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns a new string by alternating this array's values with
separator . | |||||||||||
Returns the number of values in this array.
| |||||||||||
Returns the value at
index , or null if the array has no value
at index . | |||||||||||
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. | |||||||||||
Returns the value at
index if it exists and is a boolean or can
be coerced to a boolean. | |||||||||||
Returns the value at
index if it exists and is a double or can
be coerced to a double. | |||||||||||
Returns the value at
index if it exists and is a double or can
be coerced to a double. | |||||||||||
Returns the value at
index if it exists and is an int or
can be coerced to an int. | |||||||||||
Returns the value at
index if it exists and is an int or
can be coerced to an int. | |||||||||||
Returns the value at
index if it exists and is a JSONArray . | |||||||||||
Returns the value at
index if it exists and is a JSONObject . | |||||||||||
Returns the value at
index if it exists and is a long or
can be coerced to a long. | |||||||||||
Returns the value at
index if it exists and is a long or
can be coerced to a long. | |||||||||||
Returns the value at
index if it exists, coercing it if
necessary. | |||||||||||
Returns the value at
index if it exists, coercing it if
necessary. | |||||||||||
Appends
value to the end of this array. | |||||||||||
Sets the value at
index to value , null padding this array
to the required length if necessary. | |||||||||||
Sets the value at
index to value , null padding this array
to the required length if necessary. | |||||||||||
Sets the value at
index to value , null padding this array
to the required length if necessary. | |||||||||||
Sets the value at
index to value , null padding this array
to the required length if necessary. | |||||||||||
Appends
value to the end of this array. | |||||||||||
Sets the value at
index to value , null padding this array
to the required length if necessary. | |||||||||||
Appends
value to the end of this array. | |||||||||||
Appends
value to the end of this array. | |||||||||||
Appends
value to the end of this array. | |||||||||||
Returns a new object whose values are the values in this array, and whose
names are the values in
names . | |||||||||||
Encodes this array as a compact JSON string, such as:
[94043,90210] | |||||||||||
Encodes this array as a human readable JSON string for debugging, such
as:
[ 94043, 90210 ] |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new JSONArray
by copying all values from the given
collection.
copyFrom | a collection whose values are of supported types. Unsupported values are not permitted and will yield an array in an inconsistent state. |
---|
Creates a new JSONArray
with values from the next array in the
tokener.
readFrom | a tokener whose nextValue() method will yield a
JSONArray . |
---|
JSONException | if the parse fails or doesn't yield a
JSONArray .
|
---|
Creates a new JSONArray
with values from the JSON string.
json | a JSON-encoded string containing an array. |
---|
JSONException | if the parse fails or doesn't yield a JSONArray .
|
---|
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true
only if this ==
o
. See Writing a correct equals
method
if you intend implementing your own equals
method.
The general contract for the equals
and hashCode()
methods is that if equals
returns true
for
any two objects, then hashCode()
must return the same value for
these objects. This means that subclasses of Object
usually
override either both methods or neither of them.
o | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Returns the value at index
.
JSONException | if this array has no value at index , or if
that value is the null reference. This method returns
normally if the value is JSONObject#NULL .
|
---|
Returns the value at index
if it exists and is a boolean or can
be coerced to a boolean.
JSONException | if the value at index doesn't exist or
cannot be coerced to a boolean.
|
---|
Returns the value at index
if it exists and is a double or can
be coerced to a double.
JSONException | if the value at index doesn't exist or
cannot be coerced to a double.
|
---|
Returns the value at index
if it exists and is an int or
can be coerced to an int.
JSONException | if the value at index doesn't exist or
cannot be coerced to a int.
|
---|
Returns the value at index
if it exists and is a JSONArray
.
JSONException | if the value doesn't exist or is not a JSONArray .
|
---|
Returns the value at index
if it exists and is a JSONObject
.
JSONException | if the value doesn't exist or is not a JSONObject .
|
---|
Returns the value at index
if it exists and is a long or
can be coerced to a long.
JSONException | if the value at index doesn't exist or
cannot be coerced to a long.
|
---|
Returns the value at index
if it exists, coercing it if
necessary.
JSONException | if no such value exists. |
---|
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct hashCode
method
if you intend implementing your own hashCode
method.
Returns true if this array has no value at index
, or if its value
is the null
reference or NULL
.
Returns a new string by alternating this array's values with 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"
JSONException |
---|
Returns the value at index
, or null if the array has no value
at index
.
Returns the value at index
if it exists and is a boolean or can
be coerced to a boolean. Returns false otherwise.
Returns the value at index
if it exists and is a boolean or can
be coerced to a boolean. Returns fallback
otherwise.
Returns the value at index
if it exists and is a double or can
be coerced to a double. Returns fallback
otherwise.
Returns the value at index
if it exists and is a double or can
be coerced to a double. Returns NaN
otherwise.
Returns the value at index
if it exists and is an int or
can be coerced to an int. Returns 0 otherwise.
Returns the value at index
if it exists and is an int or
can be coerced to an int. Returns fallback
otherwise.
Returns the value at index
if it exists and is a JSONArray
. Returns null otherwise.
Returns the value at index
if it exists and is a JSONObject
. Returns null otherwise.
Returns the value at index
if it exists and is a long or
can be coerced to a long. Returns fallback
otherwise.
Returns the value at index
if it exists and is a long or
can be coerced to a long. Returns 0 otherwise.
Returns the value at index
if it exists, coercing it if
necessary. Returns the empty string if no such value exists.
Returns the value at index
if it exists, coercing it if
necessary. Returns fallback
if no such value exists.
Appends value
to the end of this array.
value | a JSONObject , JSONArray , String, Boolean,
Integer, Long, Double, NULL , or null . May
not be NaNs or infinities . Unsupported values are not permitted and will cause the
array to be in an inconsistent state. |
---|
Sets the value at index
to value
, null padding this array
to the required length if necessary. If a value already exists at index
, it will be replaced.
JSONException |
---|
Sets the value at index
to value
, null padding this array
to the required length if necessary. If a value already exists at index
, it will be replaced.
JSONException |
---|
Sets the value at index
to value
, null padding this array
to the required length if necessary. If a value already exists at index
, it will be replaced.
JSONException |
---|
Sets the value at index
to value
, null padding this array
to the required length if necessary. If a value already exists at index
, it will be replaced.
value | a JSONObject , JSONArray , String, Boolean,
Integer, Long, Double, NULL , or null . May
not be NaNs or infinities . |
---|
JSONException |
---|
Appends value
to the end of this array.
Sets the value at index
to value
, null padding this array
to the required length if necessary. If a value already exists at index
, it will be replaced.
value | a finite value. May not be NaNs or
infinities . |
---|
JSONException |
---|
Appends value
to the end of this array.
Appends value
to the end of this array.
Appends value
to the end of this array.
value | a finite value. May not be NaNs or
infinities . |
---|
JSONException |
---|
Returns a new object whose values are the values in this array, and whose
names are the values in 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.
JSONException |
---|
Encodes this array as a compact JSON string, such as:
[94043,90210]
Encodes this array as a human readable JSON string for debugging, such as:
[ 94043, 90210 ]
indentSpaces | the number of spaces to indent for each level of nesting. |
---|
JSONException |
---|