Node Director
Public Member Functions | List of all members
org.json.JSONArray Class Reference

A JSONArray is an ordered sequence of values. More...

Public Member Functions

 JSONArray ()
 Construct an empty JSONArray.
 JSONArray (JSONTokener x) throws ParseException
 Construct a JSONArray from a JSONTokener.
 JSONArray (String string) throws ParseException
 Construct a JSONArray from a source string.
 JSONArray (Collection collection)
 Construct a JSONArray from a Collection.
Object get (int index) throws NoSuchElementException
 Get the object value associated with an index.
boolean getBoolean (int index) throws ClassCastException, NoSuchElementException
 Get the boolean value associated with an index.
double getDouble (int index) throws NoSuchElementException, NumberFormatException
 Get the double value associated with an index.
int getInt (int index) throws NoSuchElementException, NumberFormatException
 Get the int value associated with an index.
JSONArray getJSONArray (int index) throws NoSuchElementException
 Get the JSONArray associated with an index.
JSONObject getJSONObject (int index) throws NoSuchElementException
 Get the JSONObject associated with an index.
String getString (int index) throws NoSuchElementException
 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 length of the JSONArray.
Object opt (int index)
 Get the optional object value associated with an index.
boolean optBoolean (int index)
 Get the optional boolean value associated with an index.
boolean optBoolean (int index, boolean defaultValue)
 Get the optional boolean value associated with an index.
double optDouble (int index)
 Get the optional double value associated with an index.
double optDouble (int index, double defaultValue)
 Get the optional double value associated with an index.
int optInt (int index)
 Get the optional int value associated with an index.
int optInt (int index, int defaultValue)
 Get the optional int value associated with an index.
JSONArray optJSONArray (int index)
 Get the optional JSONArray associated with an index.
JSONObject optJSONObject (int index)
 Get the optional JSONObject associated with an index.
String optString (int index)
 Get the optional string value associated with an index.
String optString (int index, String defaultValue)
 Get the optional string associated with an index.
JSONArray put (boolean value)
 Append a boolean value.
JSONArray put (double value)
 Append a double value.
JSONArray put (int value)
 Append an int value.
JSONArray put (Object value)
 Append an object value.
JSONArray put (int index, boolean value)
 Put or replace a boolean value in the JSONArray.
JSONArray put (int index, double value)
 Put or replace a double value.
JSONArray put (int index, int value)
 Put or replace an int value.
JSONArray put (int index, Object value) throws NoSuchElementException, NullPointerException
 Put or replace an object value in the JSONArray.
JSONObject toJSONObject (JSONArray names)
 Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
String toString ()
 Make an JSON external form string of this JSONArray.
String toString (int indentFactor)
 Make a prettyprinted JSON string of this JSONArray.

Detailed Description

A JSONArray is an ordered sequence of values.

Its external form is a string wrapped in square brackets with commas between 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 external form string into an internal form Java object. The toString() method creates an external form string.

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 typing checking and type coersion for you.

The texts produced by the toString() methods are very strict. The constructors are more forgiving in the texts they will accept.

Author
JSON.org
Version
1

Constructor & Destructor Documentation

org.json.JSONArray.JSONArray ( )

Construct an empty JSONArray.

Referenced by org.json.JSONArray.optJSONArray().

org.json.JSONArray.JSONArray ( JSONTokener  x) throws ParseException

Construct a JSONArray from a JSONTokener.

Parameters
xA JSONTokener
Exceptions
ParseExceptionA JSONArray must start with '['
ParseExceptionExpected a ',' or ']'
org.json.JSONArray.JSONArray ( String  string) throws ParseException

Construct a JSONArray from a source string.

Parameters
stringA string that begins with [ (left bracket) and ends with ] (right bracket).
Exceptions
ParseExceptionThe string must conform to JSON syntax.
org.json.JSONArray.JSONArray ( Collection  collection)

Construct a JSONArray from a Collection.

Parameters
collectionA Collection.

Member Function Documentation

Object org.json.JSONArray.get ( int  index) throws NoSuchElementException

Get the object value associated with an index.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
An object value.
Exceptions
NoSuchElementException

References org.json.JSONArray.opt().

Referenced by sfi.director.application.FrontendHTTPServer.serve(), and org.json.XML.toString().

boolean org.json.JSONArray.getBoolean ( int  index) throws ClassCastException, NoSuchElementException

Get the boolean value associated with an index.

The string values "true" and "false" are converted to boolean.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The truth.
Exceptions
NoSuchElementExceptionif the index is not found
ClassCastException
double org.json.JSONArray.getDouble ( int  index) throws NoSuchElementException, NumberFormatException

Get the double value associated with an index.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The value.
Exceptions
NoSuchElementExceptionif the key is not found
NumberFormatExceptionif the value cannot be converted to a number.

Referenced by org.json.JSONArray.getInt().

int org.json.JSONArray.getInt ( int  index) throws NoSuchElementException, NumberFormatException

Get the int value associated with an index.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The value.
Exceptions
NoSuchElementExceptionif the key is not found
NumberFormatExceptionif the value cannot be converted to a number.

References org.json.JSONArray.getDouble().

JSONArray org.json.JSONArray.getJSONArray ( int  index) throws NoSuchElementException

Get the JSONArray associated with an index.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
A JSONArray value.
Exceptions
NoSuchElementExceptionif the index is not found or if the value is not a JSONArray
JSONObject org.json.JSONArray.getJSONObject ( int  index) throws NoSuchElementException

Get the JSONObject associated with an index.

Parameters
indexsubscript
Returns
A JSONObject value.
Exceptions
NoSuchElementExceptionif the index is not found or if the value is not a JSONObject
String org.json.JSONArray.getString ( int  index) throws NoSuchElementException

Get the string associated with an index.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
A string value.
Exceptions
NoSuchElementException

References org.json.JSONArray.toString().

Referenced by sfi.director.application.FrontendHTTPServer.db_event(), sfi.director.repository.DBObject.DBObject(), org.json.JSONObject.toJSONArray(), and org.json.JSONArray.toJSONObject().

boolean org.json.JSONArray.isNull ( int  index)

Determine if the value is null.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
true if the value at the index is null, or if there is no value.

References org.json.JSONArray.opt().

String org.json.JSONArray.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.

Parameters
separatorA string that will be inserted between the elements.
Returns
a string.

References org.json.JSONArray.length().

Referenced by org.json.JSONArray.toString().

int org.json.JSONArray.length ( )
Object org.json.JSONArray.opt ( int  index)
boolean org.json.JSONArray.optBoolean ( int  index)

Get the optional boolean value associated with an index.

It returns false if there is no value at that index, or if the value is not Boolean.TRUE or the String "true".

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The truth.
boolean org.json.JSONArray.optBoolean ( int  index,
boolean  defaultValue 
)

Get the optional boolean value associated with an index.

It returns the defaultValue if there is no value at that index or if it is not a Boolean or the String "true" or "false" (case insensitive).

Parameters
indexThe index must be between 0 and length() - 1.
defaultValueA boolean default.
Returns
The truth.

References org.json.JSONArray.opt().

double org.json.JSONArray.optDouble ( int  index)

Get the optional double value associated with an index.

NaN is returned if the index is not found, or if the value is not a number and cannot be converted to a number.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The value.
double org.json.JSONArray.optDouble ( int  index,
double  defaultValue 
)

Get the optional double value associated with an index.

The defaultValue is returned if the index is not found, or if the value is not a number and cannot be converted to a number.

Parameters
indexsubscript
defaultValueThe default value.
Returns
The value.

References org.json.JSONArray.opt().

int org.json.JSONArray.optInt ( int  index)

Get the optional int value associated with an index.

Zero is returned if the index is not found, or if the value is not a number and cannot be converted to a number.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
The value.
int org.json.JSONArray.optInt ( int  index,
int  defaultValue 
)

Get the optional int value associated with an index.

The defaultValue is returned if the index is not found, or if the value is not a number and cannot be converted to a number.

Parameters
indexThe index must be between 0 and length() - 1.
defaultValueThe default value.
Returns
The value.

References org.json.JSONArray.opt().

JSONArray org.json.JSONArray.optJSONArray ( int  index)

Get the optional JSONArray associated with an index.

Parameters
indexsubscript
Returns
A JSONArray value, or null if the index has no value, or if the value is not a JSONArray.

References org.json.JSONArray.JSONArray(), and org.json.JSONArray.opt().

Referenced by sfi.director.application.FrontendHTTPServer.db_event(), and sfi.director.application.FrontendHTTPServer.db_search().

JSONObject org.json.JSONArray.optJSONObject ( int  index)

Get the optional JSONObject associated with an index.

Null is returned if the key is not found, or null if the index has no value, or if the value is not a JSONObject.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
A JSONObject value.

References org.json.JSONArray.opt().

Referenced by sfi.director.application.FrontendHTTPServer.sessionProxy(), and org.json.CDL.toString().

String org.json.JSONArray.optString ( int  index)

Get the optional string value associated with an index.

It returns an empty string if there is no value at that index. If the value is not a string and is not null, then it is coverted to a string.

Parameters
indexThe index must be between 0 and length() - 1.
Returns
A String value.

Referenced by sfi.director.application.FrontendHTTPServer.db_search(), sfi.director.application.FrontendHTTPServer.handleRpc(), and sfi.director.application.FrontendHTTPServer.sessionProxy().

String org.json.JSONArray.optString ( int  index,
String  defaultValue 
)

Get the optional string associated with an index.

The defaultValue is returned if the key is not found.

Parameters
indexThe index must be between 0 and length() - 1.
defaultValueThe default value.
Returns
A String value.

References org.json.JSONArray.opt().

JSONArray org.json.JSONArray.put ( boolean  value)
JSONArray org.json.JSONArray.put ( double  value)

Append a double value.

Parameters
valueA double value.
Returns
this.

References org.json.JSONArray.put().

JSONArray org.json.JSONArray.put ( int  value)

Append an int value.

Parameters
valueAn int value.
Returns
this.

References org.json.JSONArray.put().

JSONArray org.json.JSONArray.put ( Object  value)

Append an object value.

Parameters
valueAn object value. The value should be a Boolean, Double, Integer, JSONArray, JSObject, or String, or the JSONObject.NULL object.
Returns
this.
JSONArray org.json.JSONArray.put ( int  index,
boolean  value 
)

Put or replace a boolean value in the JSONArray.

Parameters
indexsubscript The subscript. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
valueA boolean value.
Returns
this.
Exceptions
NoSuchElementExceptionThe index must not be negative.

References org.json.JSONArray.put().

JSONArray org.json.JSONArray.put ( int  index,
double  value 
)

Put or replace a double value.

Parameters
indexsubscript The subscript. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
valueA double value.
Returns
this.
Exceptions
NoSuchElementExceptionThe index must not be negative.

References org.json.JSONArray.put().

JSONArray org.json.JSONArray.put ( int  index,
int  value 
)

Put or replace an int value.

Parameters
indexsubscript The subscript. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
valueAn int value.
Returns
this.
Exceptions
NoSuchElementExceptionThe index must not be negative.

References org.json.JSONArray.put().

JSONArray org.json.JSONArray.put ( int  index,
Object  value 
) throws NoSuchElementException, NullPointerException

Put or replace an object value in the JSONArray.

Parameters
indexThe subscript. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
valueAn object value.
Returns
this.
Exceptions
NoSuchElementExceptionThe index must not be negative.
NullPointerExceptionThe index must not be null.

References org.json.JSONArray.length(), and org.json.JSONArray.put().

JSONObject org.json.JSONArray.toJSONObject ( JSONArray  names)

Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.

Parameters
namesA JSONArray containing a list of key strings. These will be paired with the values.
Returns
A JSONObject, or null if there are no names or if this JSONArray has no values.

References org.json.JSONArray.getString(), org.json.JSONArray.length(), org.json.JSONArray.opt(), and org.json.JSONObject.put().

Referenced by org.json.CDL.rowToJSONObject().

String org.json.JSONArray.toString ( )

Make an JSON external form string of this JSONArray.

For compactness, no unnecessary whitespace is added. Warning: This method assumes that the data structure is acyclical.

Returns
a printable, displayable, transmittable representation of the array.

References org.json.JSONArray.join().

Referenced by org.json.JSONArray.getString(), org.json.Test.main(), and org.json.JSONArray.toString().

String org.json.JSONArray.toString ( int  indentFactor)

Make a prettyprinted JSON string of this JSONArray.

Warning: This method assumes that the data structure is non-cyclical.

Parameters
indentFactorThe number of spaces to add to each level of indentation.
Returns
a printable, displayable, transmittable representation of the object, beginning with [ (left bracket) and ending with ] (right bracket).

References org.json.JSONArray.toString().


The documentation for this class was generated from the following file: