Home » tapestry-src-5.0.19 » org.apache.tapestry5.json » [javadoc | source]
org.apache.tapestry5.json
public final class: JSONArray [javadoc | source]
java.lang.Object
   org.apache.tapestry5.json.JSONArray
A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values. The internal form is an object having get and opt methods for accessing the values by index, and put methods for adding or replacing values. The values can be any of these types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object.

The constructor can convert a JSON text into a Java object. The toString method converts to JSON text.

A get method returns a value if one can be found, and throws an exception if one cannot be found. An opt method returns a default value instead of throwing an exception, and so is useful for obtaining optional values.

The generic get() and opt() methods return an object which you can cast or query for type. There are also typed get and opt methods that do type checking and type coersion for you.

The texts produced by the toString methods strictly conform to JSON syntax rules. The constructors are more forgiving in the texts they will accept:

Constructor:
 public JSONArray() 
 public JSONArray(String text) 
 public JSONArray(Object values) 
 JSONArray(JSONTokener tokenizer) 
    Construct a JSONArray from a JSONTokener.
    Parameters:
    tokenizer - A JSONTokener
    Throws:
    RuntimeException - If there is a syntax error.
Method from org.apache.tapestry5.json.JSONArray Summary:
equals,   get,   getBoolean,   getDouble,   getInt,   getJSONArray,   getJSONObject,   getLong,   getString,   isNull,   join,   length,   put,   put,   toArray,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.tapestry5.json.JSONArray Detail:
 public boolean equals(Object obj) 
 public Object get(int index) 
    Get the object value associated with an index.
 public boolean getBoolean(int index) 
    Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
 public double getDouble(int index) 
    Get the double value associated with an index.
 public int getInt(int index) 
    Get the int value associated with an index.
 public JSONArray getJSONArray(int index) 
    Get the JSONArray associated with an index.
 public JSONObject getJSONObject(int index) 
    Get the JSONObject associated with an index.
 public long getLong(int index) 
    Get the long value associated with an index.
 public String getString(int index) 
    Get the string associated with an index.
 public boolean isNull(int index) 
    Determine if the value is null.
 public String join(String separator) 
    Make a string from the contents of this JSONArray. The separator string is inserted between each element. Warning: This method assumes that the data structure is acyclical.
 public int length() 
    Get the number of elements in the JSONArray, included nulls.
 public JSONArray put(Object value) 
    Append an object value. This increases the array's length by one.
 public JSONArray put(int index,
    Object value) 
    Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
 Object[] toArray() 
 public String toString() 
    Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to produce a syntactically correct JSON text then null will be returned instead. This could occur if the array contains an invalid number.

    Warning: This method assumes that the data structure is acyclical.