|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface JsonArray
JsonArray class represents an immutable JSON array value.
A full JsonArray instance can be created from a input source using
JsonReader.readArray(). For example:
It can also be built from scratch using
JsonReader jsonReader = new JsonReader(...);
JsonArray array = jsonReader.readArray();
jsonReader.close();
JsonBuilder.beginArray().
For example 1:
An empty JSON array can be built as follows:
JsonArray array = new JsonBuilder()
.beginArray()
.endArray()
.build();
For example 2:
The following JSON
[
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
]
can be built using :
JsonArray array = new JsonBuilder()
.beginArray()
.beginObject()
.add("type", "home")
.add("number", "212 555-1234")
.endObject()
.beginObject()
.add("type", "home")
.add("number", "646 555-4567")
.endObject()
.endArray()
.build();
JsonArray can be written to JSON as follows:
JsonArray arr = ...;
JsonWriter writer = new JsonWriter(...)
writer.writeArray(arr);
writer.close();
JsonArray values can be JsonObject, JsonArray,
JsonString, JsonNumber, JsonValue.TRUE,
JsonValue.FALSE, JsonValue.NULL. These values can be
accessed using various accessor methods. For example:
In the above example 2, home number "212 555-1234" can be got using:
JsonObject home = array.getValue(0, JsonObject.class);
String number = home.getValue("number", JsonString.class).getValue();
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface javax.json.JsonValue |
|---|
JsonValue.JsonValueType |
| Field Summary |
|---|
| Fields inherited from interface javax.json.JsonValue |
|---|
FALSE, NULL, TRUE |
| Method Summary | ||
|---|---|---|
JsonValue |
getValue(int index)
Returns the value at the specified position in this JSON array values. |
|
|
getValue(int index,
Class<T> clazz)
Returns the value at the specified position in this JSON array values. |
|
List<JsonValue> |
getValues()
Returns an unmodifiable list of this JSON array values |
|
int |
size()
Returns the number of values in this JSON array. |
|
| Methods inherited from interface javax.json.JsonValue |
|---|
getValueType |
| Method Detail |
|---|
List<JsonValue> getValues()
int size()
JsonValue getValue(int index)
index - index of the value to return
IndexOutOfBoundsException - if the index is out of range
<T extends JsonValue> T getValue(int index,
Class<T> clazz)
index - index of the value to returnclazz - value class
IndexOutOfBoundsException - if the index is out of range
ClassCastException - if the value at the specified position is not
assignable to the type T
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||