JSONObject
JSONObject
accumulate(String key,
Object value)
Accumulate values under a key.
JSONObject
append(String key,
Object value)
Append values to the array under a key.
void
clear()
Removes all of the elements from this JSONObject.
static String
doubleToString(double d)
Produce a string from a double.
protected Set<Map.Entry<String,Object>>
entrySet()
Get a set of entries of the JSONObject.
Object
get(String key)
Get the value object associated with a key.
BigDecimal
getBigDecimal(String key)
Get the BigDecimal value associated with a key.
BigInteger
getBigInteger(String key)
Get the BigInteger value associated with a key.
boolean
getBoolean(String key)
Get the boolean value associated with a key.
double
getDouble(String key)
Get the double value associated with a key.
<E extends Enum<E>>
E
getEnum(Class<E> clazz,
String key)
Get the enum value associated with a key.
float
getFloat(String key)
Get the float value associated with a key.
int
getInt(String key)
Get the int value associated with a key.
JSONArray
getJSONArray(String key)
Get the JSONArray value associated with a key.
JSONObject
getJSONObject(String key)
Get the JSONObject value associated with a key.
long
getLong(String key)
Get the long value associated with a key.
static String[]
getNames(JSONObject jo)
Get an array of field names from a JSONObject.
static String[]
getNames(Object object)
Get an array of public field names from an Object.
Number
getNumber(String key)
Get the Number value associated with a key.
String
getString(String key)
Get the string associated with a key.
boolean
has(String key)
Determine if the JSONObject contains a specific key.
JSONObject
increment(String key)
Increment a property of a JSONObject.
protected static boolean
isDecimalNotation(String val)
Tests if the value should be tried as a decimal.
boolean
isEmpty()
Check if JSONObject is empty.
boolean
isNull(String key)
Determine if the value associated with the key is null or if there is no
value.
Iterator<String>
keys()
Get an enumeration of the keys of the JSONObject.
Set<String>
keySet()
Get a set of keys of the JSONObject.
int
length()
Get the number of keys stored in the JSONObject.
JSONArray
names()
Produce a JSONArray containing the names of the elements of this JSONObject.
static String
numberToString(Number number)
Produce a string from a Number.
Object
opt(String key)
Get an optional value associated with a key.
BigDecimal
optBigDecimal(String key,
BigDecimal defaultValue)
Get an optional BigDecimal associated with a key, or the defaultValue if there is no such key or if its value is not a number.
BigInteger
optBigInteger(String key,
BigInteger defaultValue)
Get an optional BigInteger associated with a key, or the defaultValue if there is no such key or if its value is not a number.
boolean
optBoolean(String key)
Get an optional boolean associated with a key.
boolean
optBoolean(String key,
boolean defaultValue)
Get an optional boolean associated with a key.
double
optDouble(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(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.
<E extends Enum<E>>
E
optEnum(Class<E> clazz,
String key)
Get the enum value associated with a key.
<E extends Enum<E>>
E
optEnum(Class<E> clazz,
String key,
E defaultValue)
Get the enum value associated with a key.
float
optFloat(String key)
Get the optional double value associated with an index.
float
optFloat(String key,
float defaultValue)
Get the optional double value associated with an index.
int
optInt(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(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.
JSONArray
optJSONArray(String key)
Get an optional JSONArray associated with a key.
JSONObject
optJSONObject(String key)
Get an optional JSONObject associated with a key.
long
optLong(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(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.
Number
optNumber(String key)
Get an optional Number value associated with a key, or null
if there is no such key or if the value is not a number.
Number
optNumber(String key,
Number defaultValue)
Get an optional Number value associated with a key, or the default if there
is no such key or if the value is not a number.
Object
optQuery(JSONPointer jsonPointer)
Queries and returns a value from this object using jsonPointer, or
returns null if the query fails due to a missing key.
Object
optQuery(String jsonPointer)
Queries and returns a value from this object using jsonPointer, or
returns null if the query fails due to a missing key.
String
optString(String key)
Get an optional string associated with a key.
String
optString(String key,
String defaultValue)
Get an optional string associated with a key.
JSONObject
put(String key,
boolean value)
Put a key/boolean pair in the JSONObject.
JSONObject
put(String key,
Collection<?> value)
Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced from a Collection.
JSONObject
put(String key,
double value)
Put a key/double pair in the JSONObject.
JSONObject
put(String key,
float value)
Put a key/float 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,
Map<?,?> value)
Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced from a Map.
JSONObject
put(String key,
Object value)
Put a key/value pair in the JSONObject.
JSONObject
putOnce(String key,
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(String key,
Object value)
Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
Object
query(JSONPointer jsonPointer)
Uses a user initialized JSONPointer and tries to match it to an item within this JSONObject.
Object
query(String jsonPointer)
Creates a JSONPointer using an initialization string and tries to match it to an item within this JSONObject.
static String
quote(String string)
Produce a string in double quotes with backslash sequences in all the right places.
static Writer
quote(String string,
Writer w)
Object
remove(String key)
Remove a name and its value, if present.
boolean
similar(Object other)
Determine if two JSONObjects are similar.
protected static Number
stringToNumber(String val)
Converts a string to a number using the narrowest possible type.
static Object
stringToValue(String string)
Try to convert a string into a number, boolean, or null.
static void
testValidity(Object o)
Throw an exception if the object is a NaN or infinite number.
JSONArray
toJSONArray(JSONArray names)
Produce a JSONArray containing the values of the members of this JSONObject.
Map<String,Object>
toMap()
Returns a java.util.Map containing all of the entries in this object.
String
toString()
Make a JSON text of this JSONObject.
String
toString(int indentFactor)
Make a pretty-printed JSON text of this JSONObject.
static String
valueToString(Object value)
Make a JSON text of an Object value.
static Object
wrap(Object object)
Wrap an object, if necessary.
Writer
write(Writer writer)
Write the contents of the JSONObject as JSON text to a writer.
Writer
write(Writer writer,
int indentFactor,
int indent)
Write the contents of the JSONObject as JSON text to a writer.