Logo Search packages:      
Sourcecode: libjson-java version File versions

net::sf::json::JSONObject Class Reference

Inheritance diagram for net::sf::json::JSONObject:

net::sf::json::AbstractJSON net::sf::json::JSON

List of all members.

Detailed Description

A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and put methods for adding or replacing values by name. The values can be any of these types: Boolean, JSONArray, JSONObject, Number, String, or the JSONNull object. A JSONObject constructor can be used to convert an external form JSON text into an internal form whose values can be retrieved with the get and opt methods, or to convert values into a JSON text using the element and toString methods. A get method returns a value if one can be found, and throws an exception if one cannot be found. An opt method returns a default value instead of throwing an exception, and so is useful for obtaining optional values.

The generic get() and opt() methods return an object, which you can cast or query for type. There are also typed get and opt methods that do type checking and type coersion for you.

The put methods adds values to an object. For example,

     myString = new JSONObject().put("JSON", "Hello, World!").toString();

produces the string {"JSON": "Hello, World"}.

The texts produced by the toString methods strictly conform to the JSON sysntax rules. The constructors are more forgiving in the texts they will accept:


Definition at line 139 of file JSONObject.java.

Public Member Functions

JSONObject accumulate (String key, Object value, JsonConfig jsonConfig)
JSONObject accumulate (String key, Object value)
JSONObject accumulate (String key, long value)
JSONObject accumulate (String key, int value)
JSONObject accumulate (String key, double value)
JSONObject accumulate (String key, boolean value)
void accumulateAll (Map map, JsonConfig jsonConfig)
void accumulateAll (Map map)
void clear ()
int compareTo (Object obj)
boolean containsKey (Object key)
boolean containsValue (Object value, JsonConfig jsonConfig)
boolean containsValue (Object value)
JSONObject discard (String key)
JSONObject element (String key, Object value, JsonConfig jsonConfig)
JSONObject element (String key, Object value)
JSONObject element (String key, Map value, JsonConfig jsonConfig)
JSONObject element (String key, Map value)
JSONObject element (String key, long value)
JSONObject element (String key, int value)
JSONObject element (String key, double value)
JSONObject element (String key, Collection value, JsonConfig jsonConfig)
JSONObject element (String key, Collection value)
JSONObject element (String key, boolean value)
JSONObject elementOpt (String key, Object value, JsonConfig jsonConfig)
JSONObject elementOpt (String key, Object value)
Set entrySet ()
boolean equals (Object obj)
Object get (String key)
Object get (Object key)
boolean getBoolean (String key)
double getDouble (String key)
int getInt (String key)
JSONArray getJSONArray (String key)
JSONObject getJSONObject (String key)
long getLong (String key)
String getString (String key)
boolean has (String key)
int hashCode ()
boolean isArray ()
boolean isEmpty ()
boolean isNullObject ()
 JSONObject (boolean isNull)
 JSONObject ()
Iterator keys ()
Set keySet ()
JSONArray names (JsonConfig jsonConfig)
JSONArray names ()
Object opt (String key)
boolean optBoolean (String key, boolean defaultValue)
boolean optBoolean (String key)
double optDouble (String key, double defaultValue)
double optDouble (String key)
int optInt (String key, int defaultValue)
int optInt (String key)
JSONArray optJSONArray (String key)
JSONObject optJSONObject (String key)
long optLong (String key, long defaultValue)
long optLong (String key)
String optString (String key, String defaultValue)
String optString (String key)
Object put (Object key, Object value)
void putAll (Map map, JsonConfig jsonConfig)
void putAll (Map map)
Object remove (String key)
Object remove (Object key)
int size ()
JSONArray toJSONArray (JSONArray names)
String toString (int indentFactor, int indent)
String toString (int indentFactor)
String toString ()
Collection values ()
Writer write (Writer writer)

Static Public Member Functions

static JSONObject fromObject (Object object, JsonConfig jsonConfig)
static JSONObject fromObject (Object object)
static Object toBean (JSONObject jsonObject, Object root, JsonConfig jsonConfig)
static Object toBean (JSONObject jsonObject, JsonConfig jsonConfig)
static Object toBean (JSONObject jsonObject, Class beanClass, Map classMap)
static Object toBean (JSONObject jsonObject, Class beanClass)
static Object toBean (JSONObject jsonObject)

Static Protected Member Functions

static boolean addInstance (Object instance)
static void fireArrayEndEvent (JsonConfig jsonConfig)
static void fireArrayStartEvent (JsonConfig jsonConfig)
static void fireElementAddedEvent (int index, Object element, JsonConfig jsonConfig)
static void fireErrorEvent (JSONException jsone, JsonConfig jsonConfig)
static void fireObjectEndEvent (JsonConfig jsonConfig)
static void fireObjectStartEvent (JsonConfig jsonConfig)
static void firePropertySetEvent (String key, Object value, boolean accumulated, JsonConfig jsonConfig)
static void fireWarnEvent (String warning, JsonConfig jsonConfig)
static void removeInstance (Object instance)

Private Member Functions

JSONObject _accumulate (String key, Object value, JsonConfig jsonConfig)
Object _processValue (Object value, JsonConfig jsonConfig)
JSONObject _setInternal (String key, Object value, JsonConfig jsonConfig)
Object processValue (String key, Object value, JsonConfig jsonConfig)
Object processValue (Object value, JsonConfig jsonConfig)
JSONObject setInternal (String key, Object value, JsonConfig jsonConfig)
void verifyIsNull ()

Static Private Member Functions

static JSONObject _fromBean (Object bean, JsonConfig jsonConfig)
static JSONObject _fromDynaBean (DynaBean bean, JsonConfig jsonConfig)
static JSONObject _fromJSONObject (JSONObject object, JsonConfig jsonConfig)
static JSONObject _fromJSONString (JSONString string, JsonConfig jsonConfig)
static JSONObject _fromJSONTokener (JSONTokener tokener, JsonConfig jsonConfig)
static JSONObject _fromMap (Map map, JsonConfig jsonConfig)
static JSONObject _fromString (String str, JsonConfig jsonConfig)
static Object convertPropertyValueToArray (String key, Object value, Class targetType, JsonConfig jsonConfig, Map classMap)
static Collection convertPropertyValueToCollection (String key, Object value, JsonConfig jsonConfig, String name, Map classMap, Class collectionType)
static List convertPropertyValueToList (String key, Object value, JsonConfig jsonConfig, String name, Map classMap)
static Class findTargetClass (String key, Map classMap)
static boolean isTransientField (String name, Class beanClass)
static Object morphPropertyValue (String key, Object value, Class type, Class targetType)
static void setProperty (Object bean, String key, Object value, JsonConfig jsonConfig) throws Exception
static void setValue (JSONObject jsonObject, String key, Object value, Class type, JsonConfig jsonConfig)

Private Attributes

boolean nullObject
Map properties

Static Private Attributes

static final Log log = LogFactory.getLog( JSONObject.class )

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index