public abstract class MapBasedJSONObject extends java.lang.Object implements JSONObject
EMPTY| Constructor and Description |
|---|
MapBasedJSONObject() |
| Modifier and Type | Method and Description |
|---|---|
<A extends JSONArray,O extends JSONObject> |
clone(JSONBuilder<A,O> builder) |
boolean |
equals(java.lang.Object obj) |
java.lang.Object |
get(java.lang.String key)
Get the value object associated with a key.
|
boolean |
getBoolean(java.lang.String key)
Get the boolean value associated with a key.
|
double |
getDouble(java.lang.String key)
Get the double value associated with a key.
|
java.lang.Double |
getDoubleObj(java.lang.String key)
Get the compulsory number as a Double Object throwing a JSONException if this is not possible.
|
int |
getInt(java.lang.String key)
Get the int value associated with a key.
|
JSONArray |
getJSONArray(java.lang.String key)
Get the JSONArray value associated with a key.
|
JSONObject |
getJSONObject(java.lang.String key)
Get the JSONObject value associated with a key.
|
long |
getLong(java.lang.String key)
Get the long value associated with a key.
|
protected abstract java.util.Map<java.lang.String,java.lang.Object> |
getMap() |
java.lang.String |
getString(java.lang.String key)
Get the string associated with a key.
|
boolean |
has(java.lang.String key)
Determine if the JSONObject contains a specific key.
|
int |
hashCode() |
boolean |
isNull(java.lang.String key)
Determine if the value associated with the key is null or if there is no value.
|
java.util.Iterator<java.lang.String> |
keys()
Get an enumeration of the keys of the JSONObject.
|
int |
length()
Get the number of keys stored in the JSONObject.
|
java.lang.Object |
opt(java.lang.String key)
Get an optional value associated with a key.
|
boolean |
optBoolean(java.lang.String key)
Get an optional boolean associated with a key.
|
boolean |
optBoolean(java.lang.String key,
boolean defaultValue)
Get an optional boolean associated with a key.
|
double |
optDouble(java.lang.String key)
Get an optional double associated with a key, or NaN if there is no such key or if its value is
not a number.
|
double |
optDouble(java.lang.String key,
double defaultValue)
Get an optional double associated with a key, or the defaultValue if there is no such key or if
its value is not a number.
|
java.lang.Double |
optDoubleObj(java.lang.String key,
java.lang.Double defaultValue)
Get the optional number as a Double Object returning the optional defaultValue if this is not
possible.
|
int |
optInt(java.lang.String key)
Get an optional int value associated with a key, or zero if there is no such key or if the
value is not a number.
|
int |
optInt(java.lang.String key,
int defaultValue)
Get an optional int value associated with a key, or the default if there is no such key or if
the value is not a number.
|
java.lang.Integer |
optInteger(java.lang.String key)
Get an optional Integer value associated with the key, or null if there is no such key or if
the value is not a number and the string representation cannot be parsed as an Integer.
|
java.lang.Integer |
optInteger(java.lang.String key,
java.lang.Integer defaultValue)
Get an optional Integer value associated with the key, or the specified defaultValue if there
is no such key or if the value is not a number and the string representation cannot be parsed
as an Integer.
|
JSONArray |
optJSONArray(java.lang.String key)
Get an optional JSONArray associated with a key.
|
JSONObject |
optJSONObject(java.lang.String key)
Get an optional JSONObject associated with a key.
|
long |
optLong(java.lang.String key)
Get an optional long value associated with a key, or zero if there is no such key or if the
value is not a number.
|
long |
optLong(java.lang.String key,
long defaultValue)
Get an optional long value associated with a key, or the default if there is no such key or if
the value is not a number.
|
java.lang.String |
optString(java.lang.String key)
Get an optional string associated with a key.
|
java.lang.String |
optString(java.lang.String key,
java.lang.String defaultValue)
Get an optional string associated with a key.
|
java.util.Iterator<java.lang.String> |
sortedKeys()
Get an Iterator of the keys of the JSONObject.
|
java.lang.String |
toString()
Make a JSON text of this JSONObject.
|
java.lang.String |
toString(int indentFactor)
Make a prettyprinted JSON text of this JSONObject.
|
java.lang.String |
toString(int indentFactor,
int indent)
Make a prettyprinted JSON text of this JSONObject.
|
static java.lang.String |
toString(MapBasedJSONObject jObj) |
java.lang.Appendable |
write(java.lang.Appendable buf)
Write the contents of the JSONComponent as JSON text to a writer.
|
protected abstract java.util.Map<java.lang.String,java.lang.Object> getMap()
public final java.lang.Object opt(java.lang.String key)
opt in interface JSONObjectkey - A key string.public final boolean getBoolean(java.lang.String key)
throws JSONException
getBoolean in interface JSONObjectkey - A key string.JSONException - if the value is not a Boolean or the String "true" or "false".public static java.lang.String toString(MapBasedJSONObject jObj)
public final boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.Objectpublic final java.lang.Object get(java.lang.String key)
throws JSONException
get in interface JSONObjectkey - A key string.JSONException - if the key is not found.public final double getDouble(java.lang.String key)
throws JSONException
getDouble in interface JSONObjectkey - A key string.JSONException - if the key is not found or if the value is not a Number object and cannot be
converted to a number.public final java.lang.Double optDoubleObj(java.lang.String key,
java.lang.Double defaultValue)
JSONObjectoptDoubleObj in interface JSONObjectpublic final java.lang.Double getDoubleObj(java.lang.String key)
throws JSONException
JSONObjectgetDoubleObj in interface JSONObjectJSONExceptionpublic final int getInt(java.lang.String key)
throws JSONException
getInt in interface JSONObjectkey - A key string.JSONException - if the key is not found or if the value cannot be converted to an integer.public JSONArray getJSONArray(java.lang.String key) throws JSONException
getJSONArray in interface JSONObjectkey - A key string.JSONException - if the key is not found or if the value is not a JSONArray.public JSONObject getJSONObject(java.lang.String key) throws JSONException
getJSONObject in interface JSONObjectkey - A key string.JSONException - if the key is not found or if the value is not a JSONObject.public final long getLong(java.lang.String key)
throws JSONException
getLong in interface JSONObjectkey - A key string.JSONException - if the key is not found or if the value cannot be converted to a long.public final java.lang.String getString(java.lang.String key)
throws JSONException
getString in interface JSONObjectkey - A key string.JSONException - if the key is not found.public final boolean has(java.lang.String key)
has in interface JSONObjectkey - A key string.public final boolean isNull(java.lang.String key)
isNull in interface JSONObjectkey - A key string.public final java.util.Iterator<java.lang.String> keys()
keys in interface JSONObjectpublic final int length()
length in interface JSONObjectpublic final boolean optBoolean(java.lang.String key)
optBoolean in interface JSONObjectkey - A key string.public final boolean optBoolean(java.lang.String key,
boolean defaultValue)
optBoolean in interface JSONObjectkey - A key string.defaultValue - The default.public final double optDouble(java.lang.String key)
optDouble in interface JSONObjectkey - A string which is the key.public final double optDouble(java.lang.String key,
double defaultValue)
optDouble in interface JSONObjectkey - A key string.defaultValue - The default.public final int optInt(java.lang.String key)
optInt in interface JSONObjectkey - A key string.public final int optInt(java.lang.String key,
int defaultValue)
optInt in interface JSONObjectkey - A key string.defaultValue - The default.public final java.lang.Integer optInteger(java.lang.String key,
java.lang.Integer defaultValue)
JSONObjectoptInteger in interface JSONObjectpublic final java.lang.Integer optInteger(java.lang.String key)
JSONObjectoptInteger in interface JSONObjectpublic final long optLong(java.lang.String key)
optLong in interface JSONObjectkey - A key string.public final long optLong(java.lang.String key,
long defaultValue)
optLong in interface JSONObjectkey - A key string.defaultValue - The default.public final java.lang.String optString(java.lang.String key)
optString in interface JSONObjectkey - A key string.public final java.lang.String optString(java.lang.String key,
java.lang.String defaultValue)
optString in interface JSONObjectkey - A key string.defaultValue - The default.public final java.lang.String toString()
Warning: This method assumes that the data structure is acyclical.
toString in interface JSONComponenttoString in class java.lang.Object{ (left brace) and ending with
} (right brace).public final java.lang.String toString(int indentFactor)
Warning: This method assumes that the data structure is acyclical.
toString in interface JSONComponentindentFactor - The number of spaces to add to each level of indentation.{ (left brace) and ending with
} (right brace).public final java.lang.String toString(int indentFactor,
int indent)
Warning: This method assumes that the data structure is acyclical.
toString in interface JSONComponentindentFactor - The number of spaces to add to each level of indentation.indent - The indentation of the top level.{ (left brace) and ending with }
(right brace).java.lang.RuntimeException - If the object contains an invalid number.public final java.lang.Appendable write(java.lang.Appendable buf)
throws java.io.IOException
JSONComponentWarning: This method assumes that the data structure is acyclical.
write in interface JSONComponentjava.io.IOExceptionpublic JSONArray optJSONArray(java.lang.String key)
optJSONArray in interface JSONObjectkey - A key string.public JSONObject optJSONObject(java.lang.String key)
optJSONObject in interface JSONObjectkey - A key string.public final java.util.Iterator<java.lang.String> sortedKeys()
sortedKeys in interface JSONObjectpublic <A extends JSONArray,O extends JSONObject> O clone(JSONBuilder<A,O> builder) throws JSONException
clone in interface JSONObjectJSONException