Class JSONArray
java.lang.Object
kong.unirest.core.json.JSONElement
kong.unirest.core.json.JSONArray
https://json.org/
https://tools.ietf.org/html/rfc7159#section-4
Represents a JSON Array
-
Field Summary
FieldsFields inherited from class JSONElement
MAPPER -
Constructor Summary
ConstructorsConstructorDescriptionconstruct a empty JSONArrayConstruct a JSONArray from a typed array (int[]).construct a JSONArray from a StringJSONArray(Collection<?> collection) Construct a JSONArray from a collection.JSONArray(JsonEngine.Array array) JSONArray(JsonEngine.Element jsonElement) -
Method Summary
Modifier and TypeMethodDescriptionbooleanget(int index) get the element at the index(package private) JsonEngine.ArraygetArray()getBigDecimal(int index) get a BigDecimal at a specified indexgetBigInteger(int index) get a BigInteger at a specified indexbooleangetBoolean(int index) get a boolean at a specified indexdoublegetDouble(int index) get a Double at a specified indexprivate JsonEngine.ElementgetElement(int index) <T extends Enum<T>>
Tget a enum value based on name from a specific indexfloatgetFloat(int index) get a Float at a specified indexintgetInt(int index) get a int at a specified indexgetJSONArray(int index) get a JSONArray at a specified indexgetJSONObject(int index) get a JSONObject at a specified indexlonggetLong(int index) get a long at a specified indexgetNumber(int index) get a Number at a specified indexprivate <T> TgetOrDefault(Supplier<T> supplier, T defaultValue) getString(int index) get a String at a specified indexinthashCode()booleanisEmpty()returns if the array is emptybooleanisNull(int index) Indicates if the index does not exist or it's contents are nulliterator()return the array as a string delimited by a specific tokenintlength()opt(int index) get the element at the indexoptBigDecimal(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 BigDecimaloptBigInteger(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 BigIntegerbooleanoptBoolean(int index) get a boolean at a specified indexbooleanoptBoolean(int index, boolean defaultValue) get a boolean at a specified indexdoubleoptDouble(int index) get a Double at a specified indexdoubleoptDouble(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>>
T<T extends Enum<T>>
TfloatoptFloat(int index) get a Float at a specified index, or a NaN value if the value does not exist or is not a FloatfloatoptFloat(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 FloatintoptInt(int index) get a int at a specified index, or 0 if the value does not exist or is not a intintoptInt(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 intoptJSONArray(int index) get a String at a specified index, or null if the value does not exist or is not a JSONArrayoptJSONObject(int index) get a JSONObject at a specified index or null if it does not exist or is not a valid JSONObjectlongoptLong(int index) get a long at a specified index, or 0 if the value does not exist or is not a longlongoptLong(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 longoptNumber(int index) get a Number at a specified indexget a Number at a specified indexoptString(int index) get a String at a specified index, or an empty string if the value does not exist or is not a Stringget a String at a specified index, or a default value if the value does not exist or is not a Stringput(boolean bool) add a Boolean to the arrayput(double num) add a double to the arrayput(float num) add a float to the arrayput(int num) add a int to the arrayput(int index, boolean bool) put a boolean at a specific indexput(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 nullsput(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 nullsput(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 nullsput(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 nullsput a Number at a specific instance if the index is beyond the currently length the array will be buffered with nullsput a object at a specific instance if the index is beyond the currently length the array will be buffered with nullsput a String at a specific index if the index is beyond the currently length the array will be buffered with nullsput(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 nullsput a JSONObject as a map at a specific index if the index is beyond the currently length the array will be buffered with nullsprivate JSONArrayput(int index, JsonEngine.Element o) 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 nullsput(long num) add a long to the arrayadd a Number to the arrayadd a Object to the array Must be a valid JSON type or else it will be turned into a stringadd a String to the arrayput(Collection collection) add a JSONArray to the arrayadd a JSONObject to the array as a mapappend a JSONArray as an element to the end of the arrayput(JSONObject object) append a JSONObject to the end of the arrayput(T enumValue) put a enum which will be put as the string nameremove(int index) Removes the element at the specified position in this array.booleanindicates if a JSONArray has the same elements as another JSONArrayprivate static JsonEngine.ArraytoJsonArray(Object thing) toJSONObject(JSONArray names) Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.toList()Converts the JSONArray to a ListtoString()returns the String representation of the JSONArraytoString(int indent) returns the String representation of the JSONArrayprivate <T extends Number>
TMethods inherited from class JSONElement
getElement, optQuery, optQuery, query, query, toJson, toJsonObject, toMap, toPrettyJson, toTree, write, write, writeMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
obj
-
-
Constructor Details
-
JSONArray
public JSONArray()construct a empty JSONArray -
JSONArray
construct a JSONArray from a String- Parameters:
jsonString- a JSON String
-
JSONArray
Construct a JSONArray from a collection.- Parameters:
collection- a collection which contains json types
-
JSONArray
Construct a JSONArray from a typed array (int[]).- Parameters:
array- an array type which may be typed (e.g. Object[], String[], JSONObject[])
-
JSONArray
JSONArray(JsonEngine.Array array) -
JSONArray
JSONArray(JsonEngine.Element jsonElement)
-
-
Method Details
-
toJsonArray
-
length
public int length()- Returns:
- The length of the array
-
put
append a JSONObject to the end of the array- Parameters:
object- a JSONObject- Returns:
- this JSONArray
-
put
-
put
add a double to the array- Parameters:
num- a double- Returns:
- this JSONArray
- Throws:
JSONException
-
put
add a int to the array- Parameters:
num- a int- Returns:
- this JSONArray
-
put
add a long to the array- Parameters:
num- a long- Returns:
- this JSONArray
-
put
add a float to the array- Parameters:
num- a float- Returns:
- this JSONArray
- Throws:
JSONException
-
put
-
put
add a Boolean to the array- Parameters:
bool- a Boolean- Returns:
- this JSONArray
-
put
-
put
-
put
add a JSONArray to the array- Parameters:
collection- a Collection of JSON Types- Returns:
- this JSONArray
-
put
-
put
put a long at a specific instance if the index is beyond the currently length the array will be buffered with nulls- Parameters:
index- the index position to put tonumber- a long- Returns:
- this JSONArray
- Throws:
JSONException
-
put
put a double at a specific instance if the index is beyond the currently length the array will be buffered with nulls- Parameters:
index- the index position to put tonumber- a double- Returns:
- this JSONArray
- Throws:
JSONException
-
put
put a boolean at a specific index- Parameters:
index- the index position to put tobool- a bool value- Returns:
- this JSONArray
- Throws:
JSONException
-
put
put a object at a specific instance if the index is beyond the currently length the array will be buffered with nulls- Parameters:
index- the index position to put toobject- a long- Returns:
- this JSONArray
- Throws:
JSONException- if something goes wrong
-
put
put a float at a specific instance if the index is beyond the currently length the array will be buffered with nulls- Parameters:
index- the index position to put tonumber- a Number- Returns:
- this JSONArray
- Throws:
JSONException
-
put
put a int at a specific instance if the index is beyond the currently length the array will be buffered with nulls- Parameters:
index- the index position to put tonumber- a int- Returns:
- this JSONArray
- Throws:
JSONException
-
put
-
put
-
put
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- Parameters:
index- index of the element to replacemap- a Map of String keys and values of JSON Types- Returns:
- this JSONArray
- Throws:
JSONException
-
put
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- Parameters:
index- the index position to put tocollection- a Collection of JSON types- Returns:
- this JSONArray
- Throws:
JSONException
-
put
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- Type Parameters:
T- a type of enum- Parameters:
index- the index position to put toenumValue- a enum value to put- Returns:
- this JSONArray
-
put
-
put
-
remove
Removes the element at the specified position in this array. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the array.- Parameters:
index- index the index of the element to be removed- Returns:
- the element previously at the specified position or null if the index did not exist.
-
getBoolean
get a boolean at a specified index- Parameters:
index- the array index position- Returns:
- a boolean
- Throws:
JSONException- if the element is not a boolean or index is out of bounds
-
optBoolean
public boolean optBoolean(int index) get a boolean at a specified index- Parameters:
index- the array index position- Returns:
- a boolean
-
optBoolean
public boolean optBoolean(int index, boolean defaultValue) get a boolean at a specified index- Parameters:
index- the array index positiondefaultValue- a default value if the index position does not exist or is not a boolean- Returns:
- a boolean
-
getJSONObject
get a JSONObject at a specified index- Parameters:
index- the array index position- Returns:
- a JSONObject
- Throws:
JSONException- if the element is not a JSONObject or index is out of bounds
-
optJSONObject
get a JSONObject at a specified index or null if it does not exist or is not a valid JSONObject- Parameters:
index- the array index position- Returns:
- a JSONObject
-
getDouble
get a Double at a specified index- Parameters:
index- the array index position- Returns:
- a Double
- Throws:
JSONException- if the element is not a Double or index is out of bounds
-
optDouble
public double optDouble(int index) get a Double at a specified index- Parameters:
index- the array index position- Returns:
- a Double
-
optDouble
public 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- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a Double
-
getFloat
get a Float at a specified index- Parameters:
index- the array index position- Returns:
- a Float
- Throws:
JSONException- if the element is not a Float or index is out of bounds
-
optFloat
public 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- Parameters:
index- the array index position- Returns:
- a Float
-
optFloat
public 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- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a Float
-
getLong
get a long at a specified index- Parameters:
index- the array index position- Returns:
- a long
- Throws:
JSONException- if the element is not a long or index is out of bounds
-
optLong
public long optLong(int index) get a long at a specified index, or 0 if the value does not exist or is not a long- Parameters:
index- the array index position- Returns:
- a long
-
optLong
public 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- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a long
-
getNumber
get a Number at a specified index- Parameters:
index- the array index position- Returns:
- a Number
- Throws:
JSONException- if the element is not a Number or index is out of bounds
-
optNumber
get a Number at a specified index- Parameters:
index- the array index position- Returns:
- a int
-
optNumber
-
getInt
get a int at a specified index- Parameters:
index- the array index position- Returns:
- a int
- Throws:
JSONException- if the element is not a int or index is out of bounds
-
optInt
public int optInt(int index) get a int at a specified index, or 0 if the value does not exist or is not a int- Parameters:
index- the array index position- Returns:
- a int
-
optInt
public 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- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a int
-
getBigInteger
get a BigInteger at a specified index- Parameters:
index- the array index position- Returns:
- a BigInteger
- Throws:
JSONException- if the element is not a BigInteger or index is out of bounds
-
optBigInteger
get a BigInteger at a specified index, or a default value if the value does not exist or is not a BigInteger- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a BigInteger
-
getBigDecimal
get a BigDecimal at a specified index- Parameters:
index- the array index position- Returns:
- a BigDecimal
- Throws:
JSONException- if the element is not a BigDecimal or index is out of bounds
-
optBigDecimal
get a BigDecimal at a specified index, or a default value if the value does not exist or is not a BigDecimal- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a BigDecimal
-
getString
get a String at a specified index- Parameters:
index- the array index position- Returns:
- a String
- Throws:
JSONException- if the element is not a String or index is out of bounds
-
optString
get a String at a specified index, or an empty string if the value does not exist or is not a String- Parameters:
index- the array index position- Returns:
- a String
-
optString
get a String at a specified index, or a default value if the value does not exist or is not a String- Parameters:
index- the array index positiondefaultValue- the default value to return if the index or value type are not valid- Returns:
- a String
-
getJSONArray
get a JSONArray at a specified index- Parameters:
index- the array index position- Returns:
- a JSONArray
- Throws:
JSONException- if the element is not a JSONArray or index is out of bounds
-
optJSONArray
get a String at a specified index, or null if the value does not exist or is not a JSONArray- Parameters:
index- the array index position- Returns:
- a JSONArray
-
getEnum
get a enum value based on name from a specific index- Type Parameters:
T- the type of enum- Parameters:
enumClass- the enum typeindex- the index- Returns:
- a enum value
- Throws:
JSONException- if the index is out of bounds or the value cannot be converted to the enum type
-
optEnum
-
optEnum
-
get
get the element at the index- Parameters:
index- the index number- Returns:
- the object at that position
- Throws:
JSONException- if index is out of bounds
-
opt
get the element at the index- Parameters:
index- the index number- Returns:
- the object at that position
-
toString
-
toString
returns the String representation of the JSONArray- Parameters:
indent- currently ignored until this is addressed by GSON- Returns:
- string json
- Throws:
JSONException- if something goes wrong
-
join
return the array as a string delimited by a specific token- Parameters:
token- the delimitation token- Returns:
- a token delimited array
- Throws:
JSONException- if something goes wrong
-
iterator
-
similar
indicates if a JSONArray has the same elements as another JSONArray- Parameters:
o- the other object- Returns:
- a bool
-
toList
-
isNull
public boolean isNull(int index) Indicates if the index does not exist or it's contents are null- Parameters:
index- the index poisition to test- Returns:
- boolean if the index exists
-
equals
-
hashCode
-
getArray
JsonEngine.Array getArray() -
getElement
-
getOrDefault
-
tryNumber
-
toJSONObject
Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.- Parameters:
names- A JSONArray containing a list of key strings. These will be paired with the values.- Returns:
- A JSONObject, or null if there are no names or if this JSONArray has no values.
- Throws:
JSONException- If any of the names are null.
-
isEmpty
public boolean isEmpty()returns if the array is empty- Returns:
- bool if it be empty
-