net.sourceforge.javajson
Class JsonArray

java.lang.Object
  extended by net.sourceforge.javajson.JsonArray
All Implemented Interfaces:
Iterable<JsonValue>

public class JsonArray
extends Object
implements Iterable<JsonValue>


Constructor Summary
JsonArray()
           
 
Method Summary
 JsonArray add(boolean value)
           
 JsonArray add(double value)
           
 JsonArray add(float value)
           
 JsonArray add(int value)
           
 JsonArray add(JsonArray value)
           
 JsonArray add(JsonObject value)
           
 JsonArray add(long value)
           
 JsonArray add(Object value)
           
 JsonArray add(String value)
           
 boolean getBoolean(int index)
           
 double getDouble(int index)
           
 float getFloat(int index)
           
 int getInt(int index)
           
 JsonArray getJsonArray(int index)
           
 JsonObject getJsonObject(int index)
           
 long getLong(int index)
           
 String getString(int index)
           
 boolean isBoolean(int index)
          Checks if the item at an index is a boolean.
 boolean isDouble(int index)
          Checks if the item at an index is a double.
 boolean isFloat(int index)
          Checks if the item at an index is a float.
 boolean isInt(int index)
          Checks if the item at an index is a int.
 boolean isJsonArray(int index)
          Checks if the item at an index is an array.
 boolean isJsonObject(int index)
          Checks if the item at an index is an object.
 boolean isLong(int index)
          Checks if the item at an index is a long.
 boolean isSimilar(JsonArray obj)
          Checks if the structure of this json array is similar to that of another array.
 boolean isString(int index)
          Checks if the item at an index is an string.
 Iterator<JsonValue> iterator()
           
static JsonArray parse(InputStream is)
          Parses a string to a json object.
static JsonArray parse(Reader reader)
          Parses a string to a json object.
static JsonArray parse(String input)
          Parses a string to a json object.
 int size()
           
 String toString()
           
 String toString(int spacing)
          Returns a nicely formatted string
protected  String toString(int spacing, int margin)
          Called by toString(int) to keep track of the spacing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonArray

public JsonArray()
Method Detail

parse

public static JsonArray parse(String input)
                       throws JsonException
Parses a string to a json object.

Throws:
JsonException

parse

public static JsonArray parse(Reader reader)
                       throws JsonException
Parses a string to a json object.

Throws:
JsonException

parse

public static JsonArray parse(InputStream is)
                       throws JsonException
Parses a string to a json object.

Throws:
JsonException

add

public JsonArray add(boolean value)

add

public JsonArray add(double value)

add

public JsonArray add(float value)

add

public JsonArray add(int value)

add

public JsonArray add(long value)

add

public JsonArray add(JsonArray value)

add

public JsonArray add(JsonObject value)

add

public JsonArray add(String value)

add

public JsonArray add(Object value)

getBoolean

public boolean getBoolean(int index)
Parameters:
index -
Throws:
ClassCastException - if the value cannot be converted to a boolean
IndexOutOfBoundsException - if its out of bounds

getDouble

public double getDouble(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getFloat

public float getFloat(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getInt

public int getInt(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getJsonArray

public JsonArray getJsonArray(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getJsonObject

public JsonObject getJsonObject(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getLong

public long getLong(int index)
Throws:
ClassCastException - if the value cannot be converted to a double
IndexOutOfBoundsException - if its out of bounds

getString

public String getString(int index)
Throws:
IndexOutOfBoundsException - if its out of bounds

isBoolean

public boolean isBoolean(int index)
Checks if the item at an index is a boolean. See JsonValue.isBoolean() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a boolean
Throws:
IndexOutOfBoundsException

isDouble

public boolean isDouble(int index)
Checks if the item at an index is a double. See JsonValue.isLong() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a double
Throws:
IndexOutOfBoundsException

isFloat

public boolean isFloat(int index)
Checks if the item at an index is a float. See JsonValue.isLong() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a float
Throws:
IndexOutOfBoundsException

isInt

public boolean isInt(int index)
Checks if the item at an index is a int. See JsonValue.isLong() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a int
Throws:
IndexOutOfBoundsException

isJsonArray

public boolean isJsonArray(int index)
Checks if the item at an index is an array. See JsonValue.isJsonArray() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a json array
Throws:
IndexOutOfBoundsException

isJsonObject

public boolean isJsonObject(int index)
Checks if the item at an index is an object. See JsonValue.isJsonObject() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a json object
Throws:
IndexOutOfBoundsException

isLong

public boolean isLong(int index)
Checks if the item at an index is a long. See JsonValue.isLong() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a long
Throws:
IndexOutOfBoundsException

isString

public boolean isString(int index)
Checks if the item at an index is an string. See JsonValue.isString() for more information

Parameters:
index - The index of the array to check
Returns:
True if the object contains the item and is a json string
Throws:
IndexOutOfBoundsException

isSimilar

public boolean isSimilar(JsonArray obj)
Checks if the structure of this json array is similar to that of another array. It simply checks that each item exists in both objects (same length of array) and that subobjects (json object or json array) are also similar.

Parameters:
obj -
Returns:

iterator

public Iterator<JsonValue> iterator()
Specified by:
iterator in interface Iterable<JsonValue>

size

public int size()

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(int spacing)
Returns a nicely formatted string

Parameters:
spacing -
Returns:

toString

protected String toString(int spacing,
                          int margin)
Called by toString(int) to keep track of the spacing

Parameters:
spacing -
margin -
Returns: