public final class

JsonArray

extends JsonElement
implements Iterable<T>
java.lang.Object
   ↳ com.google.gson.JsonElement
     ↳ com.google.gson.JsonArray

Class Overview

A class representing an array type in Json. An array is a list of JsonElements each of which can be of a different type. This is an ordered list, meaning that the order in which elements are added is preserved.

Summary

Public Constructors
JsonArray()
Creates an empty JsonArray.
Public Methods
void add(JsonElement element)
Adds the specified element to self.
void addAll(JsonArray array)
Adds all the elements of the specified array to self.
boolean equals(Object o)
JsonElement get(int i)
Returns the ith element of the array.
BigDecimal getAsBigDecimal()
convenience method to get this array as a BigDecimal if it contains a single element.
BigInteger getAsBigInteger()
convenience method to get this array as a BigInteger if it contains a single element.
boolean getAsBoolean()
convenience method to get this array as a boolean if it contains a single element.
byte getAsByte()
convenience method to get this element as a primitive byte value.
char getAsCharacter()
convenience method to get this element as a primitive character value.
double getAsDouble()
convenience method to get this array as a double if it contains a single element.
float getAsFloat()
convenience method to get this array as a float if it contains a single element.
int getAsInt()
convenience method to get this array as an integer if it contains a single element.
long getAsLong()
convenience method to get this array as a long if it contains a single element.
Number getAsNumber()
convenience method to get this array as a Number if it contains a single element.
short getAsShort()
convenience method to get this array as a primitive short if it contains a single element.
String getAsString()
convenience method to get this array as a String if it contains a single element.
int hashCode()
Iterator<JsonElement> iterator()
Returns an iterator to navigate the elemetns of the array.
int size()
Returns the number of elements in the array.
[Expand]
Inherited Methods
From class com.google.gson.JsonElement
From class java.lang.Object
From interface java.lang.Iterable

Public Constructors

public JsonArray ()

Creates an empty JsonArray.

Public Methods

public void add (JsonElement element)

Adds the specified element to self.

Parameters
element the element that needs to be added to the array.

public void addAll (JsonArray array)

Adds all the elements of the specified array to self.

Parameters
array the array whose elements need to be added to the array.

public boolean equals (Object o)

public JsonElement get (int i)

Returns the ith element of the array.

Parameters
i the index of the element that is being sought.
Returns
  • the element present at the ith index.
Throws
IndexOutOfBoundsException if i is negative or greater than or equal to the size() of the array.

public BigDecimal getAsBigDecimal ()

convenience method to get this array as a BigDecimal if it contains a single element.

Returns
  • get this element as a BigDecimal if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive.
NumberFormatException if the element at index 0 is not a valid BigDecimal.
IllegalStateException if the array has more than one element.

public BigInteger getAsBigInteger ()

convenience method to get this array as a BigInteger if it contains a single element.

Returns
  • get this element as a BigInteger if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive.
NumberFormatException if the element at index 0 is not a valid BigInteger.
IllegalStateException if the array has more than one element.

public boolean getAsBoolean ()

convenience method to get this array as a boolean if it contains a single element.

Returns
  • get this element as a boolean if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid boolean.
IllegalStateException if the array has more than one element.

public byte getAsByte ()

convenience method to get this element as a primitive byte value.

Returns
  • get this element as a primitive byte value.

public char getAsCharacter ()

convenience method to get this element as a primitive character value.

Returns
  • get this element as a primitive char value.

public double getAsDouble ()

convenience method to get this array as a double if it contains a single element.

Returns
  • get this element as a double if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid double.
IllegalStateException if the array has more than one element.

public float getAsFloat ()

convenience method to get this array as a float if it contains a single element.

Returns
  • get this element as a float if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid float.
IllegalStateException if the array has more than one element.

public int getAsInt ()

convenience method to get this array as an integer if it contains a single element.

Returns
  • get this element as an integer if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid integer.
IllegalStateException if the array has more than one element.

public long getAsLong ()

convenience method to get this array as a long if it contains a single element.

Returns
  • get this element as a long if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid long.
IllegalStateException if the array has more than one element.

public Number getAsNumber ()

convenience method to get this array as a Number if it contains a single element.

Returns
  • get this element as a number if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid Number.
IllegalStateException if the array has more than one element.

public short getAsShort ()

convenience method to get this array as a primitive short if it contains a single element.

Returns
  • get this element as a primitive short if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid short.
IllegalStateException if the array has more than one element.

public String getAsString ()

convenience method to get this array as a String if it contains a single element.

Returns
  • get this element as a String if it is single element array.
Throws
ClassCastException if the element in the array is of not a JsonPrimitive and is not a valid String.
IllegalStateException if the array has more than one element.

public int hashCode ()

public Iterator<JsonElement> iterator ()

Returns an iterator to navigate the elemetns of the array. Since the array is an ordered list, the iterator navigates the elements in the order they were inserted.

Returns
  • an iterator to navigate the elements of the array.

public int size ()

Returns the number of elements in the array.

Returns
  • the number of elements in the array.