public class

JSONObjWrapper

extends JSONObject
java.lang.Object
   ↳ org.json.JSONObject
     ↳ edu.stanford.junction.addon.JSONObjWrapper

Class Overview

A wrapper for JSONObjects that provides hashCode and equals methods based on the underlying JSONObject's 'id' property. Useful when you want a HashSet/HashMap of JSONObjects, and each object has a unique 'id'. Also provides deep copy and compression routines.

Summary

[Expand]
Inherited Fields
From class org.json.JSONObject
Public Constructors
JSONObjWrapper(JSONObject obj)
Public Methods
Object clone()
static String compressObj(JSONObject obj)
static JSONObject copyJSONObject(JSONObject obj)
boolean equals(Object other)
static JSONObject expandCompressedObj(String compressed)
Object get(String key)
Get the value object associated with a key.
JSONObject getRaw()
boolean has(String key)
Determine if the JSONObject contains a specific key.
int hashCode()
Iterator keys()
Get an enumeration of the keys of the JSONObject.
int length()
Get the number of keys stored in the JSONObject.
Object opt(String key)
Get an optional value associated with a key.
JSONObject put(String key, Object value)
Put a key/value pair in the JSONObject.
JSONObject put(String key, boolean value)
Put a key/boolean pair in the JSONObject.
JSONObject put(String key, int value)
Put a key/int pair in the JSONObject.
JSONObject put(String key, long value)
Put a key/long pair in the JSONObject.
JSONObject put(String key, double value)
Put a key/double pair in the JSONObject.
Object remove(String key)
Remove a name and its value, if present.
String toString(int indentFactor)
String toString()
Protected Methods
static Object copyValue(Object val)
[Expand]
Inherited Methods
From class org.json.JSONObject
From class java.lang.Object

Public Constructors

public JSONObjWrapper (JSONObject obj)

Public Methods

public Object clone ()

public static String compressObj (JSONObject obj)

public static JSONObject copyJSONObject (JSONObject obj)

public boolean equals (Object other)

public static JSONObject expandCompressedObj (String compressed)

public Object get (String key)

Get the value object associated with a key.

Parameters
key A key string.
Returns
  • The object associated with the key.
Throws
JSONException if the key is not found.

public JSONObject getRaw ()

public boolean has (String key)

Determine if the JSONObject contains a specific key.

Parameters
key A key string.
Returns
  • true if the key exists in the JSONObject.

public int hashCode ()

public Iterator keys ()

Get an enumeration of the keys of the JSONObject.

Returns
  • An iterator of the keys.

public int length ()

Get the number of keys stored in the JSONObject.

Returns
  • The number of keys in the JSONObject.

public Object opt (String key)

Get an optional value associated with a key.

Parameters
key A key string.
Returns
  • An object which is the value, or null if there is no value.

public JSONObject put (String key, Object value)

Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if it is present.

Parameters
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.
Returns
  • this.
Throws
JSONException If the value is non-finite number or if the key is null.

public JSONObject put (String key, boolean value)

Put a key/boolean pair in the JSONObject.

Parameters
key A key string.
value A boolean which is the value.
Returns
  • this.
Throws
JSONException If the key is null.

public JSONObject put (String key, int value)

Put a key/int pair in the JSONObject.

Parameters
key A key string.
value An int which is the value.
Returns
  • this.
Throws
JSONException If the key is null.

public JSONObject put (String key, long value)

Put a key/long pair in the JSONObject.

Parameters
key A key string.
value A long which is the value.
Returns
  • this.
Throws
JSONException If the key is null.

public JSONObject put (String key, double value)

Put a key/double pair in the JSONObject.

Parameters
key A key string.
value A double which is the value.
Returns
  • this.
Throws
JSONException If the key is null or if the number is invalid.

public Object remove (String key)

Remove a name and its value, if present.

Parameters
key The name to be removed.
Returns
  • The value that was associated with the name, or null if there was no value.

public String toString (int indentFactor)

Throws
JSONException

public String toString ()

Protected Methods

protected static Object copyValue (Object val)