|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> java.util.ArrayList org.apache.wink.json4j.JSONArray
public class JSONArray
Extension of ArrayList that only allows values which are JSON-able. See JSONObject for a list of valid values. Instances of this class are not thread-safe.
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
JSONArray()
Create a new instance of this class. |
|
JSONArray(java.util.Collection col)
Create a new instance of this class based off the contents of the passed in collection |
|
JSONArray(java.util.Collection col,
boolean includeSuperclass)
Create a new instance of this class based off the contents of the passed in collection |
|
JSONArray(java.io.InputStream is)
Create a new instance of this class from the data provided from the input stream. |
|
JSONArray(java.io.InputStream is,
boolean strict)
Create a new instance of this class from the data provided from the input stream. |
|
JSONArray(int initialCapacity)
Create a new instance of this class with the specified initial capacity. |
|
JSONArray(java.lang.Object[] elems)
Create a new instance of this class based off the contents of the passed object array. |
|
JSONArray(java.lang.Object[] elems,
boolean includeSuperclass)
Create a new instance of this class based off the contents of the passed object array. |
|
JSONArray(java.io.Reader rdr)
Create a new instance of this class from the data provided from the reader. |
|
JSONArray(java.io.Reader rdr,
boolean strict)
Create a new instance of this class from the data provided from the reader. |
|
JSONArray(java.lang.String str)
Create a new instance of this class from the provided JSON object string. |
|
JSONArray(java.lang.String str,
boolean strict)
Create a new instance of this class from the provided JSON object string. |
Method Summary | |
---|---|
void |
add(int index,
java.lang.Object element)
|
boolean |
add(java.lang.Object element)
|
boolean |
add(java.lang.Object element,
boolean includeSuperclass)
|
boolean |
addAll(java.util.Collection collection)
|
boolean |
addAll(int index,
java.util.Collection collection)
|
boolean |
getBoolean(int index)
Function to obtain a value at the specified index as a boolean. |
double |
getDouble(int index)
Function to obtain a value at the specified index as a double. |
java.lang.Object |
getIndex(int index)
Function to get a JSONArray entry at a specified index. |
int |
getInt(int index)
Function to obtain a value at the specified index as an int. |
JSONArray |
getJSONArray(int index)
Utility method to obtain the specified index as a JSONArray Only values that are instances of JSONArray will be returned. |
JSONObject |
getJSONObject(int index)
Utility method to obtain the specified key as a JSONObject Only values that are instances of JSONObject will be returned. |
long |
getLong(int index)
Function to obtain a value at the specified index as a long. |
short |
getShort(int index)
Function to obtain a value at the specified index as a short. |
java.lang.String |
getString(int index)
Function to obtain a value at the specified index as a string. |
boolean |
isNull(int index)
Utility function for testing if an element at index 'idx' is null or not. |
java.lang.String |
join(java.lang.String str)
Method to mimic the behavior of the JavaScript array join function |
int |
length()
Utility function that maps ArrayList.size() to length, for compatibility to other JSON parsers. |
java.lang.Object |
opt(int index)
Method to get the object at that position, or null if outside the array range. |
java.lang.Object |
opt(int index,
java.lang.Object defaultValue)
Method to get the object at that position, or null if outside the array range. |
boolean |
optBoolean(int index)
Method to obtain the value at index as an boolean, or 'false' if outside the array. |
boolean |
optBoolean(int index,
boolean defaultValue)
Method to obtain the value at index as an boolean, or 'defaultValue' if outside the array. |
double |
optDouble(int index)
Method to obtain the value at index as a double, or Double.NaN if outside the array. |
double |
optDouble(int index,
double defaultValue)
Method to obtain the value at index as a double, or Double.NaN if outside the array. |
int |
optInt(int index)
Method to obtain the value at index as an int, or '0' if outside the array. |
int |
optInt(int index,
int defaultValue)
Method to obtain the value at index as an int, or defaultValue if outside the array. |
long |
optLong(int index)
Method to obtain the value at index as a long, or '0' if outside the array. |
long |
optLong(int index,
long defaultValue)
Method to obtain the value at index as a long, or defaultValue if outside the array. |
short |
optShort(int index)
Method to obtain the value at index as a short, or '0' if outside the array. |
short |
optShort(int index,
short defaultValue)
Method to obtain the value at index as a short, or '0' if outside the array. |
java.lang.String |
optString(int index)
Method to obtain the value at index as a String, or null if outside the array. |
java.lang.String |
optString(int index,
java.lang.String defaultValue)
Method to obtain the value at index as a String, or defaultValue if outside the array. |
JSONArray |
put(boolean value)
Method to place a int into the array. |
JSONArray |
put(java.util.Collection value)
Method to place a map into the array. |
JSONArray |
put(java.util.Collection value,
boolean includeSuperclass)
Method to place a map into the array. |
JSONArray |
put(double value)
Method to place a double into the array. |
JSONArray |
put(int value)
Method to place a int into the array. |
JSONArray |
put(int index,
boolean value)
Method to place a boolean into the array. |
JSONArray |
put(int index,
java.util.Collection value)
Method to place a map into the array. |
JSONArray |
put(int index,
java.util.Collection value,
boolean includeSuperclass)
Method to place a map into the array. |
JSONArray |
put(int index,
double value)
Method to place a double into the array. |
JSONArray |
put(int index,
int value)
Method to place an int into the array. |
JSONArray |
put(int index,
long value)
Method to place a long into the array. |
JSONArray |
put(int index,
java.util.Map value)
Method to place a java.util.Map instance in the array. |
JSONArray |
put(int index,
java.util.Map value,
boolean includeSuperclass)
Method to place a java.util.Map instance in the array. |
JSONArray |
put(int index,
java.lang.Object element)
Map of java.util.ArrayList.add(int, java.lang.Object), for compatibility to other JSON parsers. |
JSONArray |
put(int index,
short value)
Method to place a short into the array. |
JSONArray |
put(long value)
Method to place a long into the array. |
JSONArray |
put(java.util.Map value)
Method to place a map into the array. |
JSONArray |
put(java.util.Map value,
boolean includeSuperclass)
Method to place a map into the array. |
JSONArray |
put(java.lang.Object element)
Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers. |
JSONArray |
put(java.lang.Object element,
boolean includeSuperclass)
Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers. |
JSONArray |
put(short value)
Method to place a short into the array. |
java.lang.Object |
set(int index,
java.lang.Object element)
|
java.lang.String |
toString()
Over-ridden toString() method. |
java.lang.String |
toString(int indentDepth)
Function to return a string of JSON text with specified indention. |
java.lang.String |
write()
Convert this object into a String of JSON text. |
java.lang.String |
write(boolean verbose)
Convert this object into a String of JSON text, specifying verbosity. |
java.lang.String |
write(int indentDepth)
Convert this array into a String of JSON text, specifying verbosity. |
java.io.OutputStream |
write(java.io.OutputStream os)
Convert this object into a stream of JSON text. |
java.io.OutputStream |
write(java.io.OutputStream os,
boolean verbose)
Convert this object into a stream of JSON text. |
java.io.OutputStream |
write(java.io.OutputStream os,
int indentDepth)
Convert this object into a String of JSON text, specifying how many spaces should be used for each indent level. |
java.io.Writer |
write(java.io.Writer writer)
Convert this object into a stream of JSON text. |
java.io.Writer |
write(java.io.Writer writer,
boolean verbose)
Convert this object into a stream of JSON text, specifying verbosity. |
java.io.Writer |
write(java.io.Writer writer,
int indentDepth)
Convert this array into a stream of JSON text, specifying verbosity. |
Methods inherited from class java.util.ArrayList |
---|
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, removeAll, retainAll |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList |
Constructor Detail |
---|
public JSONArray()
public JSONArray(int initialCapacity)
initialCapacity
- The initial size to define the array as.public JSONArray(java.util.Collection col) throws JSONException
col
- The Collection of objects to add into this array.
JSONException
- Thrown when objects in the collection are not JSONable.
java.lang.NullPointerException
- Thrown if col is null.public JSONArray(java.lang.Object[] elems) throws JSONException
elems
- The strings to add to a new JSONArray
JSONException
- Thrown when objects in the array are not JSONable.public JSONArray(java.lang.Object[] elems, boolean includeSuperclass) throws JSONException
elems
- The strings to add to a new JSONArrayincludeSuperclass
- For JavaBeans, include all superclass info.
JSONException
- Thrown when objects in the array are not JSONable.public JSONArray(java.util.Collection col, boolean includeSuperclass) throws JSONException
col
- The Collection of objects to add into this array.includeSuperclass
- For JavaBeans, include all superclass info.
JSONException
- Thrown when objects in the collection are not JSONable.
&throws NullPointerException Thrown if col is null.public JSONArray(java.lang.String str) throws JSONException
str
- The JSON array string to parse.
JSONException
- Thrown when the string passed is null, or malformed JSON..public JSONArray(java.lang.String str, boolean strict) throws JSONException
str
- The JSON array string to parse.strict
- Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
JSONException
- Thrown when the string passed is null, or malformed JSON..public JSONArray(java.io.Reader rdr) throws JSONException
rdr
- The Reader from which to read the JSON array string to parse.
JSONException
- Thrown when the string passed is null, or malformed JSON..public JSONArray(java.io.Reader rdr, boolean strict) throws JSONException
rdr
- The Reader from which to read the JSON array string to parse.strict
- Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
JSONException
- Thrown when the string passed is null, or malformed JSON..public JSONArray(java.io.InputStream is) throws JSONException
is
- The InputStream from which to read the JSON array string to parse.
JSONException
- Thrown when the string passed is null, or malformed JSON..public JSONArray(java.io.InputStream is, boolean strict) throws JSONException
is
- The InputStream from which to read the JSON array string to parse.strict
- Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
JSONException
- Thrown when the string passed is null, or malformed JSON..Method Detail |
---|
public java.lang.Object getIndex(int index) throws JSONException
index
- The position in the rray to fetch the object from
JSONException
- Thrown if the index is outside the array bounds.public void add(int index, java.lang.Object element)
add
in interface java.util.List
add
in class java.util.ArrayList
public boolean add(java.lang.Object element, boolean includeSuperclass)
public boolean add(java.lang.Object element)
add
in interface java.util.Collection
add
in interface java.util.List
add
in class java.util.ArrayList
public boolean addAll(java.util.Collection collection)
addAll
in interface java.util.Collection
addAll
in interface java.util.List
addAll
in class java.util.ArrayList
public boolean addAll(int index, java.util.Collection collection)
addAll
in interface java.util.List
addAll
in class java.util.ArrayList
public java.lang.Object set(int index, java.lang.Object element)
set
in interface java.util.List
set
in class java.util.ArrayList
public JSONArray put(int index, java.lang.Object element) throws JSONException
JSONException
- in the case of index out of bounds, etc.ArrayList.add(int, java.lang.Object)
public JSONArray put(java.lang.Object element) throws JSONException
JSONException
ArrayList.add(java.lang.Object)
public JSONArray put(java.lang.Object element, boolean includeSuperclass) throws JSONException
JSONException
ArrayList.add(java.lang.Object)
public JSONArray put(int index, java.util.Map value) throws JSONException
index
- The position in the array to place the Map (or coverted map).value
- An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
JSONException
- Thrown if the map cannot be converted to something JSONAble or the index is out of bounds.public JSONArray put(int index, java.util.Map value, boolean includeSuperclass) throws JSONException
index
- The position in the array to place the Map (or coverted map).value
- An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
JSONException
- Thrown if the map cannot be converted to something JSONAble or the index is out of bounds.public JSONArray put(java.util.Map value) throws JSONException
value
- An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
JSONException
- Thrown if the map cannot be converted to something JSONAble.public JSONArray put(java.util.Map value, boolean includeSuperclass) throws JSONException
value
- An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
JSONException
- Thrown if the map cannot be converted to something JSONAble.public JSONArray put(int index, java.util.Collection value) throws JSONException
index
- The position in the array to place the Collection.value
- An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
JSONException
- Thrown if the collection cannot be converted to something JSONAble or the index is out of bounds.public JSONArray put(int index, java.util.Collection value, boolean includeSuperclass) throws JSONException
index
- The position in the array to place the Collection.value
- An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
JSONException
- Thrown if the collection cannot be converted to something JSONAble or the index is out of bounds.public JSONArray put(java.util.Collection value) throws JSONException
value
- An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
JSONException
- Thrown if the collection cannot be converted to something JSONAble.public JSONArray put(java.util.Collection value, boolean includeSuperclass) throws JSONException
value
- An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
JSONException
- Thrown if the collection cannot be converted to something JSONAble.public JSONArray put(long value)
value
- A long
public JSONArray put(int index, long value)
index
- The position in the array to place the long.value
- A long
public JSONArray put(int value)
value
- An int
public JSONArray put(int index, int value)
index
- The position in the array to place the int.value
- An int
public JSONArray put(short value)
value
- A short
public JSONArray put(int index, short value)
index
- The position in the array to place the short.value
- A short
public JSONArray put(double value)
value
- A double
public JSONArray put(int index, double value)
index
- The position in the array to place the double.value
- A double
public JSONArray put(boolean value)
value
- A boolean
public JSONArray put(int index, boolean value)
index
- The position in the array to place the int.value
- A boolean
public boolean getBoolean(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not Boolean or a string of 'true' or 'false'public double getDouble(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not Number.public long getLong(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not Number.public int getInt(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not Number.public short getShort(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not Number.public java.lang.String getString(int index) throws JSONException
index
- The index of the item to retrieve.
JSONException
- if the index is outside the range or if the type at the position was not an object with a toString() function..public JSONObject getJSONObject(int index) throws JSONException
index
- The index to look up.
throws JSONException Thrown when the type returned by get(key) is not a JSONObject instance.
JSONException
public JSONArray getJSONArray(int index) throws JSONException
index
- The index to look up.
throws JSONException Thrown when the type returned by get(key) is not a Long instance, or cannot be converted to a long..
JSONException
public boolean isNull(int index)
public int length()
public java.io.OutputStream write(java.io.OutputStream os) throws JSONException
write
in interface JSONArtifact
os
- The output stream to write data to.
JSONException
- Thrown on IO errors during serialization.public java.io.OutputStream write(java.io.OutputStream os, boolean verbose) throws JSONException
write
in interface JSONArtifact
os
- The output stream to write data to. Output stream characters will be serialized as UTF-8.verbose
- Whether or not to write the JSON text in a verbose format.
JSONException
- Thrown on IO errors during serialization.public java.io.OutputStream write(java.io.OutputStream os, int indentDepth) throws JSONException
write
in interface JSONArtifact
indentDepth
- How many spaces to use for each indent level. Should be one to eight.
Less than one means no intending, greater than 8 and it will just use tab.
JSONException
- Thrown on IO errors during serialization.public java.io.Writer write(java.io.Writer writer) throws JSONException
write
in interface JSONArtifact
writer
- The writer which to write the JSON text to.
JSONException
- Thrown on IO errors during serialization.public java.io.Writer write(java.io.Writer writer, boolean verbose) throws JSONException
write
in interface JSONArtifact
writer
- The writer which to write the JSON text to.
JSONException
- Thrown on IO errors during serialization.public java.io.Writer write(java.io.Writer writer, int indentDepth) throws JSONException
write
in interface JSONArtifact
writer
- The writer which to write the JSON text to.indentDepth
- How many spaces to use for each indent level. Should be one to eight.
JSONException
- Thrown on IO errors during serialization.public java.lang.String write(boolean verbose) throws JSONException
write
in interface JSONArtifact
verbose
- Whether or not to write in compressed for formatted Strings.
JSONException
- Thrown on IO errors during serialization.public java.lang.String write(int indentDepth) throws JSONException
write
in interface JSONArtifact
indentDepth
- How many spaces to use for each indent level. Should be one to eight.
JSONException
- Thrown on IO errors during serialization.public java.lang.String write() throws JSONException
write
in interface JSONArtifact
JSONException
- Thrown on IO errors during serialization.public java.lang.String toString()
toString
in class java.util.AbstractCollection
public java.lang.String toString(int indentDepth) throws JSONException
JSONException
- Thrown if an error occurs during JSON generation.public java.lang.String join(java.lang.String str)
str
- The string delimiter to place between joined array elements in the output string.
public java.lang.Object opt(int index)
index
- the array index to get
public java.lang.Object opt(int index, java.lang.Object defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
public boolean optBoolean(int index)
index
- the array index to get
public boolean optBoolean(int index, boolean defaultValue)
index
- The array index to get.defaultValue
- the value to return if index is outside the array.
public int optInt(int index)
index
- the array index to get
public int optInt(int index, int defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
public long optLong(int index)
index
- the array index to get
public long optLong(int index, long defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
v* @return - value or defaultValuepublic short optShort(int index)
index
- the array index to get
public short optShort(int index, short defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
public double optDouble(int index)
index
- the array index to get
public double optDouble(int index, double defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
public java.lang.String optString(int index)
index
- the array index to get
public java.lang.String optString(int index, java.lang.String defaultValue)
index
- the array index to getdefaultValue
- the value to return if index is outside the array.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |