Interface JsonArray
- All Superinterfaces:
JsonValue
The interface that represents JSON array.
A JsonArray can be created by parsing JSON text using either
Json.parse(String) or Json.parse(char[]).
Alternatively, of(List) can be used to obtain a JsonArray.
- Since:
- 28
- External Specifications
-
Method Summary
Modifier and TypeMethodDescriptionasList()Returns an unmodifiable list of theJsonValues if thisJsonValueis an instance ofJsonArray; otherwise, throws aJsonValueException.default JsonValueget(int index) Returns theJsonValueassociated with the given index if thisJsonValueis an instance ofJsonArray; otherwise, throws aJsonValueException.static JsonArrayReturns theJsonArraywhose contents are copied from the given list ofJsonValues.Methods declared in interface JsonValue
asBoolean, asDouble, asInt, asLong, asMap, asString, get, toString, tryGet, tryValueModifier and TypeMethodDescriptiondefault booleanReturns thebooleanvalue represented by thisJsonValueif it is an instance ofJsonBoolean; otherwise, throws aJsonValueException.default doubleasDouble()Returns adoubleif thisJsonValueis an instance ofJsonNumberthat can be converted, as if byDouble.parseDouble, to a finitedoublevalue; otherwise, throws aJsonValueException.default intasInt()Returns anintif thisJsonValueis an instance ofJsonNumberthat can be converted exactly; otherwise, throws aJsonValueException.default longasLong()Returns alongif thisJsonValueis an instance ofJsonNumberthat can be converted exactly; otherwise, throws aJsonValueException.asMap()Returns an unmodifiable map ofStringtoJsonValueif thisJsonValueis an instance ofJsonObject; otherwise, throws aJsonValueException.default StringasString()Returns theStringvalue represented by thisJsonValueif it is an instance ofJsonString; otherwise, throws aJsonValueException.default JsonValueReturns theJsonValueassociated with the given member name if thisJsonValueis an instance ofJsonObject; otherwise, throws aJsonValueException.toString()Returns a String representation of thisJsonValuethat conforms to JSON syntax.Returns anOptionalcontaining the value of a given member of thisJsonObject, or an emptyOptionalif the member is absent; throwsJsonValueExceptionif thisJsonValueis not aJsonObject.tryValue()Returns anOptionalcontaining thisJsonValueif it is not an instance ofJsonNull, otherwise an emptyOptional.
-
Method Details
-
asList
Returns an unmodifiable list of theJsonValues if thisJsonValueis an instance ofJsonArray; otherwise, throws aJsonValueException. -
get
Returns theJsonValueassociated with the given index if thisJsonValueis an instance ofJsonArray; otherwise, throws aJsonValueException.- Specified by:
getin interfaceJsonValue- Parameters:
index- the index of the array- Returns:
- the
JsonValueassociated with the given index if thisJsonValueis an instance ofJsonArray; otherwise, throws aJsonValueException - Throws:
JsonValueException- if the given index is out of bounds
-
of
Returns theJsonArraywhose contents are copied from the given list ofJsonValues.- Parameters:
src- the list ofJsonValues. Non-null.- Returns:
- the
JsonArraywhose contents are copied from the given list ofJsonValues - Throws:
NullPointerException- ifsrcisnull, or contains any values that arenull
-