- java.lang.Object
-
- at.syntaxerror.json5.JSONArray
-
-
Constructor Summary
Constructors Constructor Description JSONArray()Constructs a new JSONArrayJSONArray(JSONParser parser)Constructs a new JSONArray from a JSONParserJSONArray(String source)Constructs a new JSONArray from a string
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(boolean value)Adds a value to the JSONArrayvoidadd(byte value)Adds a value to the JSONArrayvoidadd(double value)Adds a value to the JSONArrayvoidadd(float value)Adds a value to the JSONArrayvoidadd(int value)Adds a value to the JSONArrayvoidadd(long value)Adds a value to the JSONArrayvoidadd(short value)Adds a value to the JSONArrayvoidadd(JSONArray value)Adds a value to the JSONArrayvoidadd(JSONObject value)Adds a value to the JSONArrayvoidadd(Number value)Adds a value to the JSONArrayvoidadd(Object value)Adds a value to the JSONArrayvoidadd(String value)Adds a value to the JSONArrayCollection<Object>entrySet()Returns a collection of values of the JSONArray.Objectget(int index)Returns the value for a given indexObjectget(int index, Object defaults)Returns the value for a given index, or the default value if the operation is not possibleJSONArraygetArray(int index)Returns the value as a JSONArray for a given indexJSONArraygetArray(int index, JSONArray defaults)Returns the exact value as a JSONArray for a given index, or the default value if the operation is not possiblebooleangetBoolean(int index)Returns the value as a boolean for a given indexbooleangetBoolean(int index, boolean defaults)Returns the value as a boolean for a given index, or the default value if the operation is not possiblebytegetByte(int index)Returns the value as a byte for a given indexbytegetByte(int index, byte defaults)Returns the value as a byte for a given index, or the default value if the operation is not possiblebytegetByteExact(int index)Returns the exact value as a byte for a given index.bytegetByteExact(int index, byte defaults)Returns the exact value as a byte for a given index, or the default value if the operation is not possibledoublegetDouble(int index)Returns the value as a double for a given indexdoublegetDouble(int index, double defaults)Returns the value as a double for a given index, or the default value if the operation is not possibledoublegetDoubleExact(int index)Returns the exact value as a double for a given index.doublegetDoubleExact(int index, double defaults)Returns the exact value as a double for a given index, or the default value if the operation is not possiblefloatgetFloat(int index)Returns the value as a float for a given indexfloatgetFloat(int index, float defaults)Returns the value as a float for a given index, or the default value if the operation is not possiblefloatgetFloatExact(int index)Returns the exact value as a float for a given index.floatgetFloatExact(int index, float defaults)Returns the exact value as a float for a given index, or the default value if the operation is not possibleintgetInt(int index)Returns the value as an int for a given indexintgetInt(int index, int defaults)Returns the value as an int for a given index, or the default value if the operation is not possibleintgetIntExact(int index)Returns the exact value as an int for a given index.intgetIntExact(int index, int defaults)Returns the exact value as an int for a given index, or the default value if the operation is not possiblelonggetLong(int index)Returns the value as a long for a given indexlonggetLong(int index, long defaults)Returns the value as a long for a given index, or the default value if the operation is not possiblelonggetLongExact(int index)Returns the exact value as a long for a given index.longgetLongExact(int index, long defaults)Returns the exact value as a long for a given index, or the default value if the operation is not possibleNumbergetNumber(int index)Returns the value as a number for a given indexNumbergetNumber(int index, Number defaults)Returns the value as a number for a given index, or the default value if the operation is not possibleJSONObjectgetObject(int index)Returns the value as a JSONObject for a given indexJSONObjectgetObject(int index, JSONObject defaults)Returns the exact value as a JSONObject for a given index, or the default value if the operation is not possibleshortgetShort(int index)Returns the value as a short for a given indexshortgetShort(int index, short defaults)Returns the value as a short for a given index, or the default value if the operation is not possibleshortgetShortExact(int index)Returns the exact value as a short for a given index.shortgetShortExact(int index, short defaults)Returns the exact value as a short for a given index, or the default value if the operation is not possibleStringgetString(int index)Returns the value as a string for a given indexStringgetString(int index, String defaults)Returns the value as a string for a given index, or the default value if the operation is not possiblebooleanisArray(int index)Checks if the value with the specified index is a JSONArraybooleanisBoolean(int index)Checks if the value with the specified index is a booleanbooleanisNull(int index)Checks if the value with the specified index isnullbooleanisNumber(int index)Checks if the value with the specified index is a numberbooleanisObject(int index)Checks if the value with the specified index is a JSONObjectbooleanisString(int index)Checks if the value with the specified index is a stringIterator<Object>iterator()intlength()Returns the number of values in the JSONArrayvoidset(int index, boolean value)Sets the value at a given indexvoidset(int index, byte value)Sets the value at a given indexvoidset(int index, double value)Sets the value at a given indexvoidset(int index, float value)Sets the value at a given indexvoidset(int index, int value)Sets the value at a given indexvoidset(int index, long value)Sets the value at a given indexvoidset(int index, short value)Sets the value at a given indexvoidset(int index, JSONArray value)Sets the value at a given indexvoidset(int index, JSONObject value)Sets the value at a given indexvoidset(int index, Number value)Sets the value at a given indexvoidset(int index, Object value)Sets the value at a given indexvoidset(int index, String value)Sets the value at a given indexList<Object>toList()Converts the JSONArray into a list.StringtoString()Converts the JSONArray into its compact string representation.StringtoString(int indentFactor)Converts the JSONArray into its string representation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
JSONArray
public JSONArray()
Constructs a new JSONArray
-
JSONArray
public JSONArray(String source)
Constructs a new JSONArray from a string- Parameters:
source- a string
-
JSONArray
public JSONArray(JSONParser parser)
Constructs a new JSONArray from a JSONParser- Parameters:
parser- a JSONParser
-
-
Method Detail
-
toList
public List<Object> toList()
Converts the JSONArray into a list. All JSONObjects and JSONArrays contained within this JSONArray will be converted into their Map or List form as well- Returns:
- a list of the values of this array
-
entrySet
public Collection<Object> entrySet()
Returns a collection of values of the JSONArray. Modifying the collection will modify the JSONArray Use with caution.- Returns:
- a set of entries
-
length
public int length()
Returns the number of values in the JSONArray- Returns:
- the number of values
-
isNull
public boolean isNull(int index)
Checks if the value with the specified index isnull- Parameters:
index- the index- Returns:
- whether or not the value is
null - Throws:
JSONException- if the index does not exist
-
isBoolean
public boolean isBoolean(int index)
Checks if the value with the specified index is a boolean- Parameters:
index- the index- Returns:
- whether or not the value is a boolean
- Throws:
JSONException- if the index does not exist
-
isString
public boolean isString(int index)
Checks if the value with the specified index is a string- Parameters:
index- the index- Returns:
- whether or not the value is a string
- Throws:
JSONException- if the index does not exist
-
isNumber
public boolean isNumber(int index)
Checks if the value with the specified index is a number- Parameters:
index- the index- Returns:
- whether or not the value is a number
- Throws:
JSONException- if the index does not exist
-
isObject
public boolean isObject(int index)
Checks if the value with the specified index is a JSONObject- Parameters:
index- the index- Returns:
- whether or not the value is a JSONObject
- Throws:
JSONException- if the index does not exist
-
isArray
public boolean isArray(int index)
Checks if the value with the specified index is a JSONArray- Parameters:
index- the index- Returns:
- whether or not the value is a JSONArray
- Throws:
JSONException- if the index does not exist
-
get
public Object get(int index)
Returns the value for a given index- Parameters:
index- the index- Returns:
- the value
- Throws:
JSONException- if the index does not exist
-
getBoolean
public boolean getBoolean(int index)
Returns the value as a boolean for a given index- Parameters:
index- the index- Returns:
- the boolean
- Throws:
JSONException- if the index does not exist, or if the value is not a boolean
-
getString
public String getString(int index)
Returns the value as a string for a given index- Parameters:
index- the index- Returns:
- the string
- Throws:
JSONException- if the index does not exist, or if the value is not a string
-
getNumber
public Number getNumber(int index)
Returns the value as a number for a given index- Parameters:
index- the index- Returns:
- the number
- Throws:
JSONException- if the index does not exist, or if the value is not a number
-
getByte
public byte getByte(int index)
Returns the value as a byte for a given index- Parameters:
index- the index- Returns:
- the byte
- Throws:
JSONException- if the index does not exist, or if the value is not a byte
-
getShort
public short getShort(int index)
Returns the value as a short for a given index- Parameters:
index- the index- Returns:
- the short
- Throws:
JSONException- if the index does not exist, or if the value is not a short
-
getInt
public int getInt(int index)
Returns the value as an int for a given index- Parameters:
index- the index- Returns:
- the int
- Throws:
JSONException- if the index does not exist, or if the value is not an int
-
getLong
public long getLong(int index)
Returns the value as a long for a given index- Parameters:
index- the index- Returns:
- the long
- Throws:
JSONException- if the index does not exist, or if the value is not a long
-
getFloat
public float getFloat(int index)
Returns the value as a float for a given index- Parameters:
index- the index- Returns:
- the float
- Throws:
JSONException- if the index does not exist, or if the value is not a float
-
getDouble
public double getDouble(int index)
Returns the value as a double for a given index- Parameters:
index- the index- Returns:
- the double
- Throws:
JSONException- if the index does not exist, or if the value is not a double
-
getByteExact
public byte getByteExact(int index)
Returns the exact value as a byte for a given index. This fails if the value does not fit into a byte- Parameters:
index- the index- Returns:
- the byte
- Throws:
JSONException- if the index does not exist, the value is not a byte, or if the value does not fit into a byte
-
getShortExact
public short getShortExact(int index)
Returns the exact value as a short for a given index. This fails if the value does not fit into a short- Parameters:
index- the index- Returns:
- the short
- Throws:
JSONException- if the index does not exist, the value is not a short, or if the value does not fit into a short
-
getIntExact
public int getIntExact(int index)
Returns the exact value as an int for a given index. This fails if the value does not fit into an int- Parameters:
index- the index- Returns:
- the int
- Throws:
JSONException- if the index does not exist, the value is not an int, or if the value does not fit into an int
-
getLongExact
public long getLongExact(int index)
Returns the exact value as a long for a given index. This fails if the value does not fit into a long- Parameters:
index- the index- Returns:
- the long
- Throws:
JSONException- if the index does not exist, the value is not a long, or if the value does not fit into a long
-
getFloatExact
public float getFloatExact(int index)
Returns the exact value as a float for a given index. This fails if the value does not fit into a float- Parameters:
index- the index- Returns:
- the float
- Throws:
JSONException- if the index does not exist, the value is not a float, or if the value does not fit into a float
-
getDoubleExact
public double getDoubleExact(int index)
Returns the exact value as a double for a given index. This fails if the value does not fit into a double- Parameters:
index- the index- Returns:
- the double
- Throws:
JSONException- if the index does not exist, the value is not a double, or if the value does not fit into a double
-
getObject
public JSONObject getObject(int index)
Returns the value as a JSONObject for a given index- Parameters:
index- the index- Returns:
- the JSONObject
- Throws:
JSONException- if the index does not exist, or if the value is not a JSONObject
-
getArray
public JSONArray getArray(int index)
Returns the value as a JSONArray for a given index- Parameters:
index- the index- Returns:
- the JSONArray
- Throws:
JSONException- if the index does not exist, or if the value is not a JSONArray
-
get
public Object get(int index, Object defaults)
Returns the value for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the value
-
getBoolean
public boolean getBoolean(int index, boolean defaults)Returns the value as a boolean for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the boolean
-
getString
public String getString(int index, String defaults)
Returns the value as a string for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the string
-
getNumber
public Number getNumber(int index, Number defaults)
Returns the value as a number for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the number
-
getByte
public byte getByte(int index, byte defaults)Returns the value as a byte for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the byte
-
getShort
public short getShort(int index, short defaults)Returns the value as a short for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the short
-
getInt
public int getInt(int index, int defaults)Returns the value as an int for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the int
-
getLong
public long getLong(int index, long defaults)Returns the value as a long for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the long
-
getFloat
public float getFloat(int index, float defaults)Returns the value as a float for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the float
-
getDouble
public double getDouble(int index, double defaults)Returns the value as a double for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the double
-
getByteExact
public byte getByteExact(int index, byte defaults)Returns the exact value as a byte for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the byte
-
getShortExact
public short getShortExact(int index, short defaults)Returns the exact value as a short for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the short
-
getIntExact
public int getIntExact(int index, int defaults)Returns the exact value as an int for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the int
-
getLongExact
public long getLongExact(int index, long defaults)Returns the exact value as a long for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the long
-
getFloatExact
public float getFloatExact(int index, float defaults)Returns the exact value as a float for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the float
-
getDoubleExact
public double getDoubleExact(int index, double defaults)Returns the exact value as a double for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the double
-
getObject
public JSONObject getObject(int index, JSONObject defaults)
Returns the exact value as a JSONObject for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the JSONObject
-
getArray
public JSONArray getArray(int index, JSONArray defaults)
Returns the exact value as a JSONArray for a given index, or the default value if the operation is not possible- Parameters:
index- the indexdefaults- the default value- Returns:
- the JSONArray
-
add
public void add(Object value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(boolean value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(String value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(Number value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(byte value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(short value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(int value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(long value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(float value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(double value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(JSONObject value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
add
public void add(JSONArray value)
Adds a value to the JSONArray- Parameters:
value- the new value
-
set
public void set(int index, Object value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, boolean value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, String value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, Number value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, byte value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, short value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, int value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, long value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, float value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, double value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, JSONObject value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
set
public void set(int index, JSONArray value)Sets the value at a given index- Parameters:
index- the indexvalue- the new value
-
toString
public String toString(int indentFactor)
Converts the JSONArray into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each index/value pair. A factor of< 1disables pretty-printing and discards any optional whitespace characters.indentFactor = 2:[ "value", { "nested": 123 }, false }indentFactor = 0:["value",{"nested":123},false]- Parameters:
indentFactor- the indentation factor- Returns:
- the string representation
- See Also:
JSONStringify.toString(JSONArray, int)
-
-