Class JSONObject
Represents a JSON object. A JSON object is a map of string-based keys onto a
set of
JSONValue objects.
Constructors
Methods
containsKey(String) | Tests whether or not this JSONObject contains the specified key. |
get(String) | Gets the JSONValue associated with the specified key. |
isObject() | Returns this , as this is a JSONObject. |
keySet() | Returns keys for which this JSONObject has associations. |
put(String, JSONValue) | Maps the specified key to the specified value in this JSONObject. |
size() | Determines the number of keys on this object. |
toString() | Converts a JSONObject into a JSON representation that can be used to
communicate with a JSON service. |
Constructor Detail
JSONObject
public JSONObject()
JSONObject
Creates a new JSONObject from the supplied JavaScript value.
Parameters
- jsValue
-
Method Detail
containsKey
public boolean
containsKey(
String key)
Tests whether or not this JSONObject contains the specified key.
We use Object.hasOwnProperty here to verify that a given key is specified
on this object rather than a superclass (such as standard properties
defined on Object).
Parameters
- key
- the key to search for
Return Value
true
if the JSONObject contains the specified key
get
Gets the JSONValue associated with the specified key.
We use Object.hasOwnProperty here to verify that a given key is specified
on this object rather than a superclass (such as standard properties
defined on Object).
Parameters
- key
- the key to search for
Return Value
if found, the value associated with the specified key, or
null
otherwise
isObject
Returns
this
, as this is a JSONObject.
keySet
Returns keys for which this JSONObject has associations.
Return Value
array of keys for which there is a value
put
Maps the specified key to the specified value in this JSONObject. If the
specified key already has an associated value, it is overwritten.
Parameters
- key
- the key to associate with the specified value
- jsonValue
- the value to associate with this key
Return Value
if one existed, the previous value associated with the key, or
null
otherwise
size
public int size()
Determines the number of keys on this object.
toString
Converts a JSONObject into a JSON representation that can be used to
communicate with a JSON service.
Return Value
a JSON string representation of this JSONObject instance