Node Director
|
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. |
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.
,
(comma) may appear just before the closing bracket. ,
(comma) elision. '
(single quote). { } [ ] / \ : , = ; #
and if they do not look like numbers and if they are not the reserved words true
, false
, or null
. ;
as well as by ,
0-
(octal) or 0x-
(hex) prefix. #
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.
x | A JSONTokener |
ParseException | A JSONArray must start with '[' |
ParseException | Expected a ',' or ']' |
org.json.JSONArray.JSONArray | ( | String | string | ) | throws ParseException |
Construct a JSONArray from a source string.
string | A string that begins with [ (left bracket) and ends with ] (right bracket). |
ParseException | The string must conform to JSON syntax. |
org.json.JSONArray.JSONArray | ( | Collection | collection | ) |
Construct a JSONArray from a Collection.
collection | A Collection. |
Object org.json.JSONArray.get | ( | int | index | ) | throws NoSuchElementException |
Get the object value associated with an index.
index | The index must be between 0 and length() - 1. |
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.
index | The index must be between 0 and length() - 1. |
NoSuchElementException | if the index is not found |
ClassCastException |
double org.json.JSONArray.getDouble | ( | int | index | ) | throws NoSuchElementException, NumberFormatException |
Get the double value associated with an index.
index | The index must be between 0 and length() - 1. |
NoSuchElementException | if the key is not found |
NumberFormatException | if 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.
index | The index must be between 0 and length() - 1. |
NoSuchElementException | if the key is not found |
NumberFormatException | if the value cannot be converted to a number. |
References org.json.JSONArray.getDouble().
JSONArray org.json.JSONArray.getJSONArray | ( | int | index | ) | throws NoSuchElementException |
JSONObject org.json.JSONArray.getJSONObject | ( | int | index | ) | throws NoSuchElementException |
Get the JSONObject associated with an index.
index | subscript |
NoSuchElementException | if 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.
index | The index must be between 0 and length() - 1. |
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.
index | The index must be between 0 and length() - 1. |
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.
separator | A string that will be inserted between the elements. |
References org.json.JSONArray.length().
Referenced by org.json.JSONArray.toString().
int org.json.JSONArray.length | ( | ) |
Get the length of the JSONArray.
Referenced by sfi.director.application.FrontendHTTPServer.db_event(), sfi.director.application.FrontendHTTPServer.db_search(), sfi.director.repository.DBObject.DBObject(), sfi.director.application.FrontendHTTPServer.file_upload(), org.json.JSONArray.join(), org.json.JSONObject.names(), org.json.JSONArray.opt(), org.json.JSONArray.put(), org.json.CDL.rowToString(), sfi.director.application.FrontendHTTPServer.serve(), org.json.CDL.toJSONArray(), org.json.JSONObject.toJSONArray(), org.json.JSONArray.toJSONObject(), org.json.CDL.toString(), and org.json.XML.toString().
Object org.json.JSONArray.opt | ( | int | index | ) |
Get the optional object value associated with an index.
index | The index must be between 0 and length() - 1. |
References org.json.JSONArray.length().
Referenced by org.json.JSONArray.get(), org.json.JSONArray.isNull(), org.json.JSONArray.optBoolean(), org.json.JSONArray.optDouble(), org.json.JSONArray.optInt(), org.json.JSONArray.optJSONArray(), org.json.JSONArray.optJSONObject(), org.json.JSONArray.optString(), org.json.CDL.rowToString(), org.json.JSONArray.toJSONObject(), and org.json.XML.toString().
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".
index | The index must be between 0 and length() - 1. |
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).
index | The index must be between 0 and length() - 1. |
defaultValue | A boolean default. |
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.
index | The index must be between 0 and length() - 1. |
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.
index | subscript |
defaultValue | The default 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.
index | The index must be between 0 and length() - 1. |
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.
index | The index must be between 0 and length() - 1. |
defaultValue | The default value. |
References org.json.JSONArray.opt().
JSONArray org.json.JSONArray.optJSONArray | ( | int | index | ) |
Get the optional JSONArray associated with an index.
index | subscript |
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.
index | The index must be between 0 and length() - 1. |
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.
index | The index must be between 0 and length() - 1. |
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.
index | The index must be between 0 and length() - 1. |
defaultValue | The default value. |
References org.json.JSONArray.opt().
JSONArray org.json.JSONArray.put | ( | boolean | value | ) |
Append a boolean value.
value | A boolean value. |
Referenced by org.json.JSONObject.accumulate(), sfi.director.application.FrontendHTTPServer.db_listevents(), sfi.director.application.FrontendHTTPServer.db_searchget(), sfi.director.application.FrontendHTTPServer.edit_data(), sfi.director.application.FrontendHTTPServer.fieldsToJSON(), sfi.director.application.FrontendHTTPServer.file_upload(), org.json.Test.main(), org.json.JSONObject.names(), org.json.JSONArray.put(), org.json.CDL.rowToJSONArray(), sfi.director.application.FrontendHTTPServer.serve(), org.json.CDL.toJSONArray(), org.json.JSONObject.toJSONArray(), and sfi.director.application.FrontendHTTPServer.util_logOverview().
JSONArray org.json.JSONArray.put | ( | double | value | ) |
Append a double value.
value | A double value. |
References org.json.JSONArray.put().
JSONArray org.json.JSONArray.put | ( | int | value | ) |
Append an int value.
value | An int value. |
References org.json.JSONArray.put().
JSONArray org.json.JSONArray.put | ( | Object | value | ) |
Append an object value.
value | An object value. The value should be a Boolean, Double, Integer, JSONArray, JSObject, or String, or the JSONObject.NULL object. |
JSONArray org.json.JSONArray.put | ( | int | index, |
boolean | value | ||
) |
Put or replace a boolean value in the JSONArray.
index | subscript 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. |
value | A boolean value. |
NoSuchElementException | The 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.
index | subscript 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. |
value | A double value. |
NoSuchElementException | The 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.
index | subscript 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. |
value | An int value. |
NoSuchElementException | The 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.
index | 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. |
value | An object value. |
NoSuchElementException | The index must not be negative. |
NullPointerException | The 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.
names | A JSONArray containing a list of key strings. These will be paired with the 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.
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.
indentFactor | The number of spaces to add to each level of indentation. |
[
(left bracket) and ending with ]
(right bracket). References org.json.JSONArray.toString().