|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.tapestry.json.JSONArray
public final class 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.
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: , (comma) may appear
just before the closing bracket.null value will be inserted when there is
, (comma) elision.' (single quote).{ } [ ] / \ : , = ; # and if they do not look like numbers and if they are not
the reserved words true, false, or null.; (semicolon) as well as by , (comma).0- (octal) or 0x- (hex) prefix.
| Constructor Summary | |
|---|---|
JSONArray()
Construct an empty JSONArray. |
|
JSONArray(String text)
|
|
| Method Summary | |
|---|---|
boolean |
equals(Object obj)
|
Object |
get(int index)
Get the object value associated with an index. |
boolean |
getBoolean(int index)
Get the boolean value associated with an index. |
double |
getDouble(int index)
Get the double value associated with an index. |
int |
getInt(int index)
Get the int value associated with an index. |
JSONArray |
getJSONArray(int index)
Get the JSONArray associated with an index. |
JSONObject |
getJSONObject(int index)
Get the JSONObject associated with an index. |
long |
getLong(int index)
Get the long value associated with an index. |
String |
getString(int index)
Get the string associated with an index. |
boolean |
isNull(int index)
Determine if the value is null. |
String |
join(String separator)
Make a string from the contents of this JSONArray. |
int |
length()
Get the number of elements in the JSONArray, included nulls. |
JSONArray |
put(int index,
Object value)
Put or replace an object value in the JSONArray. |
JSONArray |
put(Object value)
Append an object value. |
String |
toString()
Make a JSON text of this JSONArray. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JSONArray()
public JSONArray(String text)
| Method Detail |
|---|
public Object get(int index)
index - The index must be between 0 and length() - 1.
RuntimeException - If there is no value for the index.public boolean getBoolean(int index)
index - The index must be between 0 and length() - 1.
RuntimeException - If there is no value for the index or if the value is not convertable to boolean.public double getDouble(int index)
index - The index must be between 0 and length() - 1.
IllegalArgumentException - If the key is not found or if the value cannot be converted to a number.public int getInt(int index)
index - The index must be between 0 and length() - 1.
IllegalArgumentException - If the key is not found or if the value cannot be converted to a number. if the
value cannot be converted to a number.public JSONArray getJSONArray(int index)
index - The index must be between 0 and length() - 1.
RuntimeException - If there is no value for the index. or if the value is not a JSONArraypublic JSONObject getJSONObject(int index)
index - subscript
RuntimeException - If there is no value for the index or if the value is not a JSONObjectpublic long getLong(int index)
index - The index must be between 0 and length() - 1.
IllegalArgumentException - If the key is not found or if the value cannot be converted to a number.public String getString(int index)
index - The index must be between 0 and length() - 1.
RuntimeException - If there is no value for the index.public boolean isNull(int index)
index - The index must be between 0 and length() - 1.
public String join(String separator)
separator string is inserted between each
element. Warning: This method assumes that the data structure is acyclical.
separator - A string that will be inserted between the elements.
RuntimeException - If the array contains an invalid number.public int length()
public JSONArray put(Object value)
value - An object value. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or
String, or the JSONObject.NULL object.
public JSONArray put(int index,
Object value)
index - The subscript.value - The value to put into the array. The value should be a Boolean, Double, Integer, JSONArray,
JSONObject, Long, or String, or the JSONObject.NULL object.
RuntimeException - If the index is negative or if the the value is an invalid number.public String toString()
toString in class Objectpublic boolean equals(Object obj)
equals in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||