public class JSONArray extends JSONElement implements Iterable<Object>
MAPPER
Constructor and Description |
---|
JSONArray()
construct a empty JSONArray
|
JSONArray(Collection<?> collection)
Construct a JSONArray from a collection.
|
JSONArray(Object array)
Construct a JSONArray from a typed array (int[]).
|
JSONArray(String jsonString)
construct a JSONArray from a String
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Object |
get(int index)
get the element at the index
|
BigDecimal |
getBigDecimal(int index)
get a BigDecimal at a specified index
|
BigInteger |
getBigInteger(int index)
get a BigInteger at a specified index
|
boolean |
getBoolean(int index)
get a boolean at a specified index
|
double |
getDouble(int index)
get a Double at a specified index
|
<T extends Enum<T>> |
getEnum(Class<T> enumClass,
int index)
get a enum value based on name from a specific index
|
float |
getFloat(int index)
get a Float at a specified index
|
int |
getInt(int index)
get a int at a specified index
|
JSONArray |
getJSONArray(int index)
get a JSONArray at a specified index
|
JSONObject |
getJSONObject(int index)
get a JSONObject at a specified index
|
long |
getLong(int index)
get a long at a specified index
|
Number |
getNumber(int index)
get a Number at a specified index
|
String |
getString(int index)
get a String at a specified index
|
int |
hashCode() |
boolean |
isEmpty()
returns if the array is empty
|
boolean |
isNull(int index)
Indicates if the index does not exist or it's contents are null
|
Iterator<Object> |
iterator() |
String |
join(String token)
return the array as a string delimited by a specific token
|
int |
length() |
Object |
opt(int index)
get the element at the index
|
BigDecimal |
optBigDecimal(int index,
BigDecimal defaultValue)
get a BigDecimal at a specified index, or a default value
if the value does not exist or is not a BigDecimal
|
BigInteger |
optBigInteger(int index,
BigInteger defaultValue)
get a BigInteger at a specified index, or a default value
if the value does not exist or is not a BigInteger
|
boolean |
optBoolean(int index)
get a boolean at a specified index
|
boolean |
optBoolean(int index,
boolean defaultValue)
get a boolean at a specified index
|
double |
optDouble(int index)
get a Double at a specified index
|
double |
optDouble(int index,
double defaultValue)
get a Double at a specified index, or a default value
if the value does not exist or is not a double
|
<T extends Enum<T>> |
optEnum(Class<T> enumClass,
int index) |
<T extends Enum<T>> |
optEnum(Class<T> enumClass,
int index,
T defaultValue) |
float |
optFloat(int index)
get a Float at a specified index, or a NaN value
if the value does not exist or is not a Float
|
float |
optFloat(int index,
float defaultValue)
get a Float at a specified index, or a default value
if the value does not exist or is not a Float
|
int |
optInt(int index)
get a int at a specified index, or 0
if the value does not exist or is not a int
|
int |
optInt(int index,
int defaultValue)
get a int at a specified index, or a default value
if the value does not exist or is not a int
|
JSONArray |
optJSONArray(int index)
get a String at a specified index, or null
if the value does not exist or is not a JSONArray
|
JSONObject |
optJSONObject(int index)
get a JSONObject at a specified index or null if it does not exist
or is not a valid JSONObject
|
long |
optLong(int index)
get a long at a specified index, or 0
if the value does not exist or is not a long
|
long |
optLong(int index,
long defaultValue)
get a long at a specified index, or a default value
if the value does not exist or is not a long
|
Number |
optNumber(int index)
get a Number at a specified index
|
Number |
optNumber(int index,
Number defaultValue)
get a Number at a specified index
|
String |
optString(int index)
get a String at a specified index, or an empty string
if the value does not exist or is not a String
|
String |
optString(int index,
String defaultValue)
get a String at a specified index, or a default value
if the value does not exist or is not a String
|
JSONArray |
put(boolean bool)
add a Boolean to the array
|
JSONArray |
put(Collection collection)
add a JSONArray to the array
|
JSONArray |
put(double num)
add a double to the array
|
JSONArray |
put(float num)
add a float to the array
|
JSONArray |
put(int num)
add a int to the array
|
JSONArray |
put(int index,
boolean bool)
put a boolean at a specific index
|
JSONArray |
put(int index,
Collection collection)
put a JSONArray at a specific index as a Collection
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
double number)
put a double at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
float number)
put a float at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
int number)
put a int at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
long number)
put a long at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
Map map)
put a JSONObject as a map at a specific index
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
Number number)
put a Number at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
Object object)
put a object at a specific instance
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(int index,
String string)
put a String at a specific index
if the index is beyond the currently length the array will be buffered with nulls
|
<T extends Enum> |
put(int index,
T enumValue)
put a Enum name at a specific index as a string
if the index is beyond the currently length the array will be buffered with nulls
|
JSONArray |
put(JSONArray array)
append a JSONArray as an element to the end of the array
|
JSONArray |
put(JSONObject object)
append a JSONObject to the end of the array
|
JSONArray |
put(long num)
add a long to the array
|
JSONArray |
put(Map map)
add a JSONObject to the array as a map
|
JSONArray |
put(Number num)
add a Number to the array
|
JSONArray |
put(Object object)
add a Object to the array
Must be a valid JSON type or else it will be turned into a string
|
JSONArray |
put(String str)
add a String to the array
|
<T extends Enum> |
put(T enumValue)
put a enum which will be put as the string name
|
Object |
remove(int index)
Removes the element at the specified position in this array.
|
boolean |
similar(Object o)
indicates if a JSONArray has the same elements as another JSONArray
|
JSONObject |
toJSONObject(JSONArray names)
Produce a JSONObject by combining a JSONArray of names with the values of
this JSONArray.
|
List |
toList()
Converts the JSONArray to a List
|
String |
toString()
returns the String representation of the JSONArray
|
String |
toString(int indent)
returns the String representation of the JSONArray
|
optQuery, optQuery, query, query, write, write
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public JSONArray()
public JSONArray(String jsonString)
jsonString
- a JSON Stringpublic JSONArray(Collection<?> collection)
collection
- a collection which contains json typespublic JSONArray(Object array)
array
- an array type which may be typed (e.g. Object[], String[], JSONObject[])public int length()
public JSONArray put(JSONObject object)
object
- a JSONObjectpublic JSONArray put(JSONArray array)
array
- a JSONArraypublic JSONArray put(double num) throws JSONException
num
- a doubleJSONException
public JSONArray put(int num)
num
- a intpublic JSONArray put(long num)
num
- a longpublic JSONArray put(float num) throws JSONException
num
- a floatJSONException
public JSONArray put(Number num)
num
- a Numberpublic JSONArray put(boolean bool)
bool
- a Booleanpublic JSONArray put(String str)
str
- a Stringpublic JSONArray put(Map map)
map
- a Map which should contain String keys and JSON types for valuespublic JSONArray put(Collection collection)
collection
- a Collection of JSON Typespublic <T extends Enum> JSONArray put(T enumValue)
T
- a enum typeenumValue
- a enumpublic JSONArray put(int index, long number) throws JSONException
index
- the index position to put tonumber
- a longJSONException
public JSONArray put(int index, double number) throws JSONException
index
- the index position to put tonumber
- a doubleJSONException
public JSONArray put(int index, boolean bool) throws JSONException
index
- the index position to put tobool
- a bool valueJSONException
public JSONArray put(int index, Object object) throws JSONException
index
- the index position to put toobject
- a longJSONException
- if something goes wrongpublic JSONArray put(int index, float number) throws JSONException
index
- the index position to put tonumber
- a NumberJSONException
public JSONArray put(int index, int number) throws JSONException
index
- the index position to put tonumber
- a intJSONException
public JSONArray put(int index, Number number)
index
- the index position to put tonumber
- a Numberpublic JSONArray put(int index, String string)
index
- the index position to put tostring
- a Stringpublic JSONArray put(int index, Map map) throws JSONException
index
- index of the element to replacemap
- a Map of String keys and values of JSON TypesJSONException
public JSONArray put(int index, Collection collection) throws JSONException
index
- the index position to put tocollection
- a Collection of JSON typesJSONException
public <T extends Enum> JSONArray put(int index, T enumValue)
T
- a type of enumindex
- the index position to put toenumValue
- a enum value to putpublic JSONArray put(Object object)
object
- the JSON Typed objectpublic Object remove(int index)
index
- index the index of the element to be removedpublic boolean getBoolean(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a boolean or index is out of boundspublic boolean optBoolean(int index)
index
- the array index positionpublic boolean optBoolean(int index, boolean defaultValue)
index
- the array index positiondefaultValue
- a default value if the index position does not exist or is not a booleanpublic JSONObject getJSONObject(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a JSONObject or index is out of boundspublic JSONObject optJSONObject(int index)
index
- the array index positionpublic double getDouble(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a Double or index is out of boundspublic double optDouble(int index)
index
- the array index positionpublic double optDouble(int index, double defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic float getFloat(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a Float or index is out of boundspublic float optFloat(int index)
index
- the array index positionpublic float optFloat(int index, float defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic long getLong(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a long or index is out of boundspublic long optLong(int index)
index
- the array index positionpublic long optLong(int index, long defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic Number getNumber(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a Number or index is out of boundspublic Number optNumber(int index)
index
- the array index positionpublic Number optNumber(int index, Number defaultValue)
index
- the array index positiondefaultValue
- the default value if the index does not exist or is not a numberpublic int getInt(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a int or index is out of boundspublic int optInt(int index)
index
- the array index positionpublic int optInt(int index, int defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic BigInteger getBigInteger(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a BigInteger or index is out of boundspublic BigInteger optBigInteger(int index, BigInteger defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic BigDecimal getBigDecimal(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a BigDecimal or index is out of boundspublic BigDecimal optBigDecimal(int index, BigDecimal defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic String getString(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a String or index is out of boundspublic String optString(int index)
index
- the array index positionpublic String optString(int index, String defaultValue)
index
- the array index positiondefaultValue
- the default value to return if the index or value type are not validpublic JSONArray getJSONArray(int index) throws JSONException
index
- the array index positionJSONException
- if the element is not a JSONArray or index is out of boundspublic JSONArray optJSONArray(int index)
index
- the array index positionpublic <T extends Enum<T>> T getEnum(Class<T> enumClass, int index) throws JSONException
T
- the type of enumenumClass
- the enum typeindex
- the indexJSONException
- if the index is out of bounds or the value cannot be converted to the enum typepublic Object get(int index) throws JSONException
index
- the index numberJSONException
- if index is out of boundspublic Object opt(int index)
index
- the index numberpublic String toString()
public String toString(int indent) throws JSONException
indent
- currently ignored until this is addressed by GSONJSONException
- if something goes wrongpublic String join(String token) throws JSONException
token
- the delimitation tokenJSONException
- if something goes wrongpublic boolean similar(Object o)
o
- the other objectpublic List toList()
public boolean isNull(int index)
index
- the index poisition to testpublic JSONObject toJSONObject(JSONArray names) throws JSONException
names
- A JSONArray containing a list of key strings. These will be paired with the values.JSONException
- If any of the names are null.public boolean isEmpty()
Copyright © 2020. All rights reserved.