public class

JSONObject

extends JSONValue
java.lang.Object
   ↳ com.google.gwt.json.client.JSONValue
     ↳ com.google.gwt.json.client.JSONObject

Class Overview

Represents a JSON object. A JSON object consists of a set of properties.

Summary

Public Constructors
JSONObject()
JSONObject(JavaScriptObject jsValue)
Creates a new JSONObject from the supplied JavaScript value.
Public Methods
boolean containsKey(String key)
Tests whether or not this JSONObject contains the specified property.
boolean equals(Object other)
Returns true if other is a JSONObject wrapping the same underlying object.
JSONValue get(String key)
Gets the JSONValue associated with the specified property.
JavaScriptObject getJavaScriptObject()
Returns the underlying JavaScript object that this object wraps.
int hashCode()
JSONObject isObject()
Returns this, as this is a JSONObject.
Set<String> keySet()
Returns the set of properties defined on this JSONObject.
JSONValue put(String key, JSONValue jsonValue)
Assign the specified property to the specified value in this JSONObject.
int size()
Determines the number of properties on this object.
String toString()
Converts a JSONObject into a JSON representation that can be used to communicate with a JSON service.
[Expand]
Inherited Methods
From class com.google.gwt.json.client.JSONValue
From class java.lang.Object

Public Constructors

public JSONObject ()

public JSONObject (JavaScriptObject jsValue)

Creates a new JSONObject from the supplied JavaScript value.

Public Methods

public boolean containsKey (String key)

Tests whether or not this JSONObject contains the specified property.

Parameters
key the property to search for
Returns
  • true if the JSONObject contains the specified property

public boolean equals (Object other)

Returns true if other is a JSONObject wrapping the same underlying object.

public JSONValue get (String key)

Gets the JSONValue associated with the specified property.

Parameters
key the property to access
Returns
  • the value of the specified property, or null if the property does not exist
Throws
NullPointerException if key is null

public JavaScriptObject getJavaScriptObject ()

Returns the underlying JavaScript object that this object wraps.

public int hashCode ()

public JSONObject isObject ()

Returns this, as this is a JSONObject.

Returns
  • a reference to a JSONObject if this JSONValue is a JSONObject or null otherwise.

public Set<String> keySet ()

Returns the set of properties defined on this JSONObject. The returned set is immutable.

public JSONValue put (String key, JSONValue jsonValue)

Assign the specified property to the specified value in this JSONObject. If the property already has an associated value, it is overwritten.

Parameters
key the property to assign
jsonValue the value to assign
Returns
  • the previous value of the property, or null if the property did not exist
Throws
NullPointerException if key is null

public int size ()

Determines the number of properties on this object.

public String toString ()

Converts a JSONObject into a JSON representation that can be used to communicate with a JSON service.

Returns
  • a JSON string representation of this JSONObject instance