Methods Summary |
---|
public boolean | equals(java.lang.Object object)
if (!(object instanceof JSONArray)) return false;
return myArrayList.equals(((JSONArray)object).myArrayList);
|
public java.lang.Object | get(int index)Get the object value associated with an index.
Object o = opt(index);
if (o == null) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
return o;
|
public boolean | getBoolean(int index)Get the boolean value associated with an index.
The string values "true" and "false" are converted to boolean.
Object o = get(index);
if (o.equals(Boolean.FALSE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("false"))) {
return false;
} else if (o.equals(Boolean.TRUE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
|
public double | getDouble(int index)Get the double value associated with an index.
Object o = get(index);
try {
return o instanceof Number ?
((Number)o).doubleValue() : Double.parseDouble((String)o);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index +
"] is not a number.");
}
|
public int | getInt(int index)Get the int value associated with an index.
Object o = get(index);
return o instanceof Number ?
((Number)o).intValue() : (int)getDouble(index);
|
public org.json.JSONArray | getJSONArray(int index)Get the JSONArray associated with an index.
Object o = get(index);
if (o instanceof JSONArray) {
return (JSONArray)o;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONArray.");
|
public org.json.JSONObject | getJSONObject(int index)Get the JSONObject associated with an index.
Object o = get(index);
if (o instanceof JSONObject) {
return (JSONObject)o;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONObject.");
|
public long | getLong(int index)Get the long value associated with an index.
Object o = get(index);
return o instanceof Number ?
((Number)o).longValue() : (long)getDouble(index);
|
public java.lang.String | getString(int index)Get the string associated with an index.
return get(index).toString();
|
public boolean | isNull(int index)Determine if the value is null.
return JSONObject.NULL.equals(opt(index));
|
public java.lang.String | join(java.lang.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.
int len = length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
}
return sb.toString();
|
public int | length()Get the number of elements in the JSONArray, included nulls.
return this.myArrayList.size();
|
public java.lang.Object | opt(int index)Get the optional object value associated with an index.
return (index < 0 || index >= length()) ?
null : this.myArrayList.get(index);
|
public boolean | 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".
return optBoolean(index, false);
|
public boolean | 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).
try {
return getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
|
public double | optDouble(int index)Get the optional double value associated with an index.
NaN is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
return optDouble(index, Double.NaN);
|
public double | optDouble(int index, double defaultValue)Get the optional double value associated with an index.
The defaultValue is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
try {
return getDouble(index);
} catch (Exception e) {
return defaultValue;
}
|
public int | optInt(int index)Get the optional int value associated with an index.
Zero is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
return optInt(index, 0);
|
public int | optInt(int index, int defaultValue)Get the optional int value associated with an index.
The defaultValue is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
try {
return getInt(index);
} catch (Exception e) {
return defaultValue;
}
|
public org.json.JSONArray | optJSONArray(int index)Get the optional JSONArray associated with an index.
Object o = opt(index);
return o instanceof JSONArray ? (JSONArray)o : null;
|
public org.json.JSONObject | 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.
Object o = opt(index);
return o instanceof JSONObject ? (JSONObject)o : null;
|
public long | optLong(int index)Get the optional long value associated with an index.
Zero is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
return optLong(index, 0);
|
public long | optLong(int index, long defaultValue)Get the optional long value associated with an index.
The defaultValue is returned if there is no value for the index,
or if the value is not a number and cannot be converted to a number.
try {
return getLong(index);
} catch (Exception e) {
return defaultValue;
}
|
public java.lang.String | 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.
return optString(index, "");
|
public java.lang.String | optString(int index, java.lang.String defaultValue)Get the optional string associated with an index.
The defaultValue is returned if the key is not found.
Object o = opt(index);
return o != null ? o.toString() : defaultValue;
|
public org.json.JSONArray | put(boolean value)Append a boolean value. This increases the array's length by one.
put(Boolean.valueOf(value));
return this;
|
public org.json.JSONArray | put(double value)Append a double value. This increases the array's length by one.
Double d = new Double(value);
JSONObject.testValidity(d);
put(d);
return this;
|
public org.json.JSONArray | put(int value)Append an int value. This increases the array's length by one.
put(new Integer(value));
return this;
|
public org.json.JSONArray | put(long value)Append an long value. This increases the array's length by one.
put(new Long(value));
return this;
|
public org.json.JSONArray | put(java.lang.Object value)Append an object value. This increases the array's length by one.
this.myArrayList.add(value);
return this;
|
public org.json.JSONArray | put(int index, boolean value)Put or replace a boolean 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.
put(index, Boolean.valueOf(value));
return this;
|
public org.json.JSONArray | put(int index, double value)Put or replace a double value. If the index is greater than the length of
the JSONArray, then null elements will be added as necessary to pad
it out.
put(index, new Double(value));
return this;
|
public org.json.JSONArray | put(int index, int value)Put or replace an int value. If the index is greater than the length of
the JSONArray, then null elements will be added as necessary to pad
it out.
put(index, new Integer(value));
return this;
|
public org.json.JSONArray | put(int index, long value)Put or replace a long value. If the index is greater than the length of
the JSONArray, then null elements will be added as necessary to pad
it out.
put(index, new Long(value));
return this;
|
public org.json.JSONArray | put(int index, java.lang.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.
JSONObject.testValidity(value);
if (index < 0) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < length()) {
this.myArrayList.set(index, value);
} else {
while (index != length()) {
put(null);
}
put(value);
}
return this;
|
public org.json.JSONObject | toJSONObject(org.json.JSONArray names)Produce a JSONObject by combining a JSONArray of names with the values
of this JSONArray.
if (names == null || names.length() == 0 || length() == 0) {
return null;
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
|
public java.lang.String | toString()Make an 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.
try {
return '[" + join(",") + ']";
} catch (Exception e) {
return null;
}
|
public java.lang.String | toString(int indentFactor)Make a prettyprinted JSON text of this JSONArray.
Warning: This method assumes that the data structure is acyclical.
return toString(indentFactor, 0);
|
java.lang.String | toString(int indentFactor, int indent)Make a prettyprinted JSON text of this JSONArray.
Warning: This method assumes that the data structure is acyclical.
int len = length();
if (len == 0) {
return "[]";
}
int i;
StringBuilder sb = new StringBuilder("[");
if (len == 1) {
sb.append(JSONObject.valueToString(this.myArrayList.get(0),
indentFactor, indent));
} else {
int newindent = indent + indentFactor;
sb.append('\n");
for (i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(",\n");
}
for (int j = 0; j < newindent; j += 1) {
sb.append(' ");
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i),
indentFactor, newindent));
}
sb.append('\n");
for (i = 0; i < indent; i += 1) {
sb.append(' ");
}
}
sb.append(']");
return sb.toString();
|