Package com.oorian.json
Class JsonArray
java.lang.Object
com.oorian.json.JsonValue
com.oorian.json.JsonArray
Represents a JSON array containing an ordered collection of values.
JsonArray provides methods for storing, retrieving, and iterating over JSON array elements. It supports all JSON value types and provides convenient methods for extracting typed arrays of primitive values.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty JsonArray.Creates a JsonArray initialized with the elements from the specified collection. -
Method Summary
Modifier and TypeMethodDescriptionAdds a value to this array.addAll(Collection<? extends Object> values) Adds all values from a collection to this array.voidclear()Removes all elements from this array.get(int index) Returns the element at the specified index.getAll()Returns a copy of all elements in this array.getAsBoolean(int index) Returns the element at the specified index as a Boolean.doublegetAsDouble(int index) Returns the element at the specified index as a double.floatgetAsFloat(int index) Returns the element at the specified index as a float.intgetAsInt(int index) Returns the element at the specified index as an int.getAsJsonArray(int index) Returns the element at the specified index as aJsonArray.getAsJsonObject(int index) Returns the element at the specified index as aJsonObject.longgetAsLong(int index) Returns the element at the specified index as a long.shortgetAsShort(int index) Returns the element at the specified index as a short.getAsString(int index) Returns the element at the specified index as a String.Returns all elements as a list of Booleans.Returns all elements as a list of Doubles.Returns all elements as a list of Floats.Returns all elements as a list of Integers.Returns all elements as a list of Longs.Returns all elements as a list of JsonObjects.Returns all elements as a list of Shorts.Returns all elements as a list of Strings.voidinitialize(String json) Replaces this array's contents by parsing a JSON string.booleanisEmpty()Returnstrueif this array contains no elements.iterator()static JsonArrayParses a JSON string into a JsonArray.parseBooleans(String json) Parses a JSON array string and returns the elements as a list of Booleans.parseDoubles(String json) Parses a JSON array string and returns the elements as a list of Doubles.parseFloats(String json) Parses a JSON array string and returns the elements as a list of Floats.Parses a JSON array string and returns the elements as a list of Integers.parseLongs(String json) Parses a JSON array string and returns the elements as a list of Longs.parseShorts(String json) Parses a JSON array string and returns the elements as a list of Shorts.parseStrings(String json) Parses a JSON array string and returns the elements as a list of Strings.intsize()Returns the number of elements in this array.Returns this value serialized as a JSON string.Methods inherited from class com.oorian.json.JsonValue
asArray, asBoolean, asNumber, asObject, asString, isArray, isNumber, isObject, isString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
JsonArray
public JsonArray()Creates an empty JsonArray. -
JsonArray
Creates a JsonArray initialized with the elements from the specified collection.- Parameters:
c- the collection of initial elements.
-
-
Method Details
-
parse
Parses a JSON string into a JsonArray.- Parameters:
json- the JSON string to parse.- Returns:
- the parsed JsonArray.
-
parseStrings
Parses a JSON array string and returns the elements as a list of Strings.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of String values.
-
parseInts
Parses a JSON array string and returns the elements as a list of Integers.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Integer values.
-
parseLongs
Parses a JSON array string and returns the elements as a list of Longs.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Long values.
-
parseShorts
Parses a JSON array string and returns the elements as a list of Shorts.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Short values.
-
parseFloats
Parses a JSON array string and returns the elements as a list of Floats.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Float values.
-
parseDoubles
Parses a JSON array string and returns the elements as a list of Doubles.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Double values.
-
parseBooleans
Parses a JSON array string and returns the elements as a list of Booleans.- Parameters:
json- the JSON array string to parse.- Returns:
- the list of Boolean values.
-
initialize
Replaces this array's contents by parsing a JSON string.- Parameters:
json- the JSON string to parse.
-
add
Adds a value to this array.- Parameters:
value- the value to add (automatically wrapped to the appropriate JSON type).- Returns:
- this JsonArray for method chaining.
-
addAll
Adds all values from a collection to this array.- Parameters:
values- the collection of values to add.- Returns:
- this JsonArray for method chaining.
-
size
public int size()Returns the number of elements in this array.- Returns:
- the element count.
-
isEmpty
public boolean isEmpty()Returnstrueif this array contains no elements.- Returns:
trueif empty.
-
clear
public void clear()Removes all elements from this array. -
getAll
Returns a copy of all elements in this array.- Returns:
- the list of all JsonValue elements.
-
getStringArray
Returns all elements as a list of Strings.- Returns:
- the list of String values.
-
getBooleanArray
Returns all elements as a list of Booleans.- Returns:
- the list of Boolean values.
-
getShortArray
Returns all elements as a list of Shorts.- Returns:
- the list of Short values.
-
getIntArray
Returns all elements as a list of Integers.- Returns:
- the list of Integer values.
-
getLongArray
Returns all elements as a list of Longs.- Returns:
- the list of Long values.
-
getFloatArray
Returns all elements as a list of Floats.- Returns:
- the list of Float values.
-
getDoubleArray
Returns all elements as a list of Doubles.- Returns:
- the list of Double values.
-
getObjectArray
Returns all elements as a list of JsonObjects.- Returns:
- the list of JsonObject values.
-
get
Returns the element at the specified index.- Parameters:
index- the zero-based index.- Returns:
- the JsonValue at that index.
-
getAsString
Returns the element at the specified index as a String.- Parameters:
index- the zero-based index.- Returns:
- the String value.
-
getAsBoolean
Returns the element at the specified index as a Boolean.- Parameters:
index- the zero-based index.- Returns:
- the Boolean value.
-
getAsShort
public short getAsShort(int index) Returns the element at the specified index as a short.- Parameters:
index- the zero-based index.- Returns:
- the short value.
-
getAsInt
public int getAsInt(int index) Returns the element at the specified index as an int.- Parameters:
index- the zero-based index.- Returns:
- the int value.
-
getAsLong
public long getAsLong(int index) Returns the element at the specified index as a long.- Parameters:
index- the zero-based index.- Returns:
- the long value.
-
getAsFloat
public float getAsFloat(int index) Returns the element at the specified index as a float.- Parameters:
index- the zero-based index.- Returns:
- the float value.
-
getAsDouble
public double getAsDouble(int index) Returns the element at the specified index as a double.- Parameters:
index- the zero-based index.- Returns:
- the double value.
-
getAsJsonObject
Returns the element at the specified index as aJsonObject.- Parameters:
index- the zero-based index.- Returns:
- the JsonObject value.
-
getAsJsonArray
Returns the element at the specified index as aJsonArray.- Parameters:
index- the zero-based index.- Returns:
- the JsonArray value.
-
toJsonString
Description copied from class:JsonValueReturns this value serialized as a JSON string.- Specified by:
toJsonStringin classJsonValue- Returns:
- the JSON string representation.
-
iterator
-