public interface JSONObject extends JSONComponent
| Modifier and Type | Field and Description |
|---|---|
static JSONObject |
EMPTY
Deprecated.
in preference of
ImmutableJSON.emptyJSONObject() |
| Modifier and Type | Method and Description |
|---|---|
<A extends JSONArray,O extends JSONObject> |
clone(JSONBuilder<A,O> builder) |
boolean |
equalsMap(java.util.Map<java.lang.String,java.lang.Object> map) |
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.
|
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.
|
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.
|
JSONObject |
put(java.lang.String key,
boolean value)
Put a key/boolean pair in the JSONObject.
|
JSONObject |
put(java.lang.String key,
double value)
Put a key/double pair in the JSONObject.
|
JSONObject |
put(java.lang.String key,
int value)
Put a key/int pair in the JSONObject.
|
JSONObject |
put(java.lang.String key,
long value)
Put a key/long pair in the JSONObject.
|
JSONObject |
put(java.lang.String key,
java.lang.Object value)
Put a key/value pair in the JSONObject.
|
JSONObject |
putOnce(java.lang.String key,
java.lang.Object value)
Put a key/value pair in the JSONObject, but only if the key and the value are both non-null,
and only if there is not already a member with that name.
|
JSONObject |
putOpt(java.lang.String key,
java.lang.Object value)
Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
|
java.lang.Object |
remove(java.lang.String key)
Remove a name and its value, if present.
|
java.util.Iterator<java.lang.String> |
sortedKeys()
Get an enumeration of the keys of the JSONObject.
|
toString, toString, toString, write@Deprecated static final JSONObject EMPTY
ImmutableJSON.emptyJSONObject()boolean equalsMap(java.util.Map<java.lang.String,java.lang.Object> map)
<A extends JSONArray,O extends JSONObject> O clone(JSONBuilder<A,O> builder) throws JSONException
JSONExceptionjava.lang.Object get(java.lang.String key)
throws JSONException
key - A key string.JSONException - if the key is not found.boolean getBoolean(java.lang.String key)
throws JSONException
key - A key string.JSONException - if the value is not a Boolean or the String "true" or "false".double getDouble(java.lang.String key)
throws JSONException
key - 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.int getInt(java.lang.String key)
throws JSONException
key - A key string.JSONException - if the key is not found or if the value cannot be converted to an integer.JSONArray getJSONArray(java.lang.String key) throws JSONException
key - A key string.JSONException - if the key is not found or if the value is not a JSONArray.JSONObject getJSONObject(java.lang.String key) throws JSONException
key - A key string.JSONException - if the key is not found or if the value is not a JSONObject.long getLong(java.lang.String key)
throws JSONException
key - A key string.JSONException - if the key is not found or if the value cannot be converted to a long.java.lang.String getString(java.lang.String key)
throws JSONException
key - A key string.JSONException - if the key is not found.boolean has(java.lang.String key)
key - A key string.boolean isNull(java.lang.String key)
key - A key string.java.util.Iterator<java.lang.String> keys()
int length()
java.lang.Object opt(java.lang.String key)
key - A key string.boolean optBoolean(java.lang.String key)
key - A key string.boolean optBoolean(java.lang.String key,
boolean defaultValue)
key - A key string.defaultValue - The default.double optDouble(java.lang.String key)
key - A string which is the key.double optDouble(java.lang.String key,
double defaultValue)
key - A key string.defaultValue - The default.java.lang.Double getDoubleObj(java.lang.String key)
throws JSONException
JSONExceptionjava.lang.Double optDoubleObj(java.lang.String key,
java.lang.Double defaultValue)
int optInt(java.lang.String key)
key - A key string.java.lang.Integer optInteger(java.lang.String key)
int optInt(java.lang.String key,
int defaultValue)
key - A key string.defaultValue - The default.java.lang.Integer optInteger(java.lang.String key,
java.lang.Integer defaultValue)
JSONArray optJSONArray(java.lang.String key)
key - A key string.JSONObject optJSONObject(java.lang.String key)
key - A key string.long optLong(java.lang.String key)
key - A key string.long optLong(java.lang.String key,
long defaultValue)
key - A key string.defaultValue - The default.java.lang.String optString(java.lang.String key)
key - A key string.java.lang.String optString(java.lang.String key,
java.lang.String defaultValue)
key - A key string.defaultValue - The default.JSONObject put(java.lang.String key, boolean value) throws JSONException
key - A key string.value - A boolean which is the value.JSONException - If the key is null.JSONObject put(java.lang.String key, double value) throws JSONException
key - A key string.value - A double which is the value.JSONException - If the key is null or if the number is invalid.JSONObject put(java.lang.String key, int value) throws JSONException
key - A key string.value - An int which is the value.JSONException - If the key is null.JSONObject put(java.lang.String key, long value) throws JSONException
key - A key string.value - A long which is the value.JSONException - If the key is null.JSONObject put(java.lang.String key, java.lang.Object value) throws JSONException
key - A key string.value - An object which is the value. It should be of one of these types: Boolean, Double,
Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.JSONException - If the value is non-finite number or if the key is null.JSONObject putOnce(java.lang.String key, java.lang.Object value) throws JSONException
key - value - JSONException - if the key is a duplicateJSONObject putOpt(java.lang.String key, java.lang.Object value) throws JSONException
key - A key string.value - An object which is the value. It should be of one of these types: Boolean, Double,
Integer, JSONArray, JSONObject, Long, String, or the JSONObject.NULL object.JSONException - If the value is a non-finite number.java.lang.Object remove(java.lang.String key)
key - The name to be removed.java.util.Iterator<java.lang.String> sortedKeys()