class JsonArray : JsonValue, MutableIterable<JsonValue>
Represents a JSON array, an ordered collection of JSON values.
Elements can be added using the add(...)
methods which accept instances of
JsonValue, strings, primitive numbers, and boolean values. To replace an element of an
array, use the set(int, ...)
methods.
Elements can be accessed by their index using .get. This class also supports iterating over the elements in document order using an .iterator or an enhanced for loop:
An equivalent List can be obtained from the method .values.
Note that this class is not thread-safe. If multiple threads access a
JsonArray
instance concurrently, while at least one of these threads modifies the
contents of this array, access to the instance must be synchronized externally. Failure to do so
may lead to an inconsistent state.
This class is not supposed to be extended by clients.
JsonArray()
Creates a new empty JsonArray. JsonArray(array: JsonArray)
Creates a new JsonArray with the contents of the specified JSON array. |
val isArray: Boolean
Detects whether this value represents a JSON array. If this is the case, this value is an instance of JsonArray. |
|
val isEmpty: Boolean
Returns |
open val isBoolean: Boolean
Detects whether this value represents a boolean value. |
|
open val isFalse: Boolean
Detects whether this value represents the JSON literal |
|
open val isNull: Boolean
Detects whether this value represents the JSON literal |
|
open val isNumber: Boolean
Detects whether this value represents a JSON number. |
|
open val isObject: Boolean
Detects whether this value represents a JSON object. If this is the case, this value is an instance of JsonObject. |
|
open val isString: Boolean
Detects whether this value represents a JSON string. |
|
open val isTrue: Boolean
Detects whether this value represents the JSON literal |
fun add(value: Int): JsonArray
Appends the JSON representation of the specified fun add(value: Long): JsonArray
Appends the JSON representation of the specified fun add(value: Float): JsonArray
Appends the JSON representation of the specified fun add(value: Double): JsonArray
Appends the JSON representation of the specified fun add(value: Boolean): JsonArray
Appends the JSON representation of the specified fun add(value: String): JsonArray
Appends the JSON representation of the specified string to the end of this array. fun add(value: JsonValue?): JsonArray
Appends the specified JSON value to the end of this array. |
|
fun asArray(): JsonArray
Returns this JSON value as JsonArray, assuming that this value represents a JSON array. If this is not the case, an exception is thrown. |
|
fun equals(other: Any?): Boolean
Indicates whether a given object is "equal to" this JsonArray. An object is considered equal
if it is also a |
|
operator fun get(index: Int): JsonValue
Returns the value of the element at the specified position in this array. |
|
fun hashCode(): Int |
|
fun iterator(): MutableIterator<JsonValue>
Returns an iterator over the values of this array in document order. The returned iterator cannot be used to modify this array. |
|
fun remove(index: Int): JsonArray
Removes the element at the specified index from this array. |
|
operator fun set(index: Int, value: Int): JsonArray
Replaces the element at the specified position in this array with the JSON representation of
the specified operator fun set(index: Int, value: Long): JsonArray
Replaces the element at the specified position in this array with the JSON representation of
the specified operator fun set(index: Int, value: Float): JsonArray
Replaces the element at the specified position in this array with the JSON representation of
the specified operator fun set(index: Int, value: Double): JsonArray
Replaces the element at the specified position in this array with the JSON representation of
the specified operator fun set(index: Int, value: Boolean): JsonArray
Replaces the element at the specified position in this array with the JSON representation of
the specified operator fun set(index: Int, value: String): JsonArray
Replaces the element at the specified position in this array with the JSON representation of the specified string. operator fun set(index: Int, value: JsonValue?): JsonArray
Replaces the element at the specified position in this array with the specified JSON value. |
|
fun size(): Int
Returns the number of elements in this array. |
|
fun values(): List<JsonValue>
Returns a list of the values in this array in document order. The returned list is backed by this array and will reflect subsequent changes. It cannot be used to modify this array. Attempts to modify the returned list will result in an exception. |
open fun asBoolean(): Boolean
Returns this JSON value as a |
|
open fun asDouble(): Double
Returns this JSON value as a |
|
open fun asFloat(): Float
Returns this JSON value as a |
|
open fun asInt(): Int
Returns this JSON value as an |
|
open fun asLong(): Long
Returns this JSON value as a |
|
open fun asObject(): JsonObject
Returns this JSON value as JsonObject, assuming that this value represents a JSON object. If this is not the case, an exception is thrown. |
|
open fun asString(): String
Returns this JSON value as String, assuming that this value represents a JSON string. If this is not the case, an exception is thrown. |
|
open fun toString(): String
Returns the JSON string for this value in its minimal form, without any additional whitespace. The result is guaranteed to be a valid input for the method Json.parse and to create a value that is equal to this object. fun toString(config: WriterConfig): String
Returns the JSON string for this value using the given formatting. |
|
fun writeTo(writer: Writer?, config: WriterConfig? = WriterConfig.MINIMAL): Unit
Writes the JSON representation of this value to the given writer using the given formatting. |
fun
Reads a JSON array from the given reader. fun
Reads a JSON array from the given string. |
|
fun unmodifiableArray(array: JsonArray): JsonArray
Returns an unmodifiable wrapper for the specified JsonArray. This method allows to provide read-only access to a JsonArray. |