public class JsonObject extends SimpleKeyValueList<java.lang.String,java.lang.Object> implements StringItem, Entity
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 JsonObject.NULL 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
put 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
coercion for you. The opt methods differ from the get methods in that they do
not throw. Instead, they return a specified value, such as null.
The put methods add or replace values in 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 syntax rules. The constructors are more forgiving in the texts they
will accept:
, (comma) may appear just
before the closing brace.' (single
quote).{} [ ] / \ : , = ; # and if they do not look like numbers and
if they are not the reserved words true, false, or
null.= or => as well as
by :.; (semicolon) as
well as by , (comma).ALLOWDUPLICATE, ALLOWEMPTYVALUE, BIDI, BIG_KEY, BIG_VALUE, CASESENSITIVE, DELETED, elements, emptyArray, flag, MAP, MAXDELETED, MAXUSEDLIST, MINHASHINGSIZE, MINSIZE, MINUSEDLIST, READONLY, SIZE_BIG, SMALL_KEY, SMALL_VALUE, VISIBLE| Constructor and Description |
|---|
JsonObject() |
| Modifier and Type | Method and Description |
|---|---|
JsonObject |
addToList(java.lang.String key,
java.lang.Object value)
Accumulate values under a key.
|
JsonArray |
getJsonArray(java.lang.String key)
Get the JsonArray value associated with a key.
|
JsonObject |
getJsonObject(java.lang.String key)
Get the JsonObject value associated with a key.
|
long |
getLong(java.lang.String key)
Get the JsonObject value associated with a key.
|
BaseItem |
getNewList(boolean keyValue)
Get a new Instance of JsonArray, JsonObject
|
boolean |
has(java.lang.String key) |
java.lang.String |
toString()
Make a JSON text of this JsonObject.
|
java.lang.String |
toString(int indentFactor)
Make a prettyprinted JSON text of this JsonObject.
|
java.lang.String |
toString(int indentFactor,
int indent) |
JsonObject |
withEntity(SimpleKeyValueList<?,?> entity)
Tokener to init the JsonObject
|
JsonObject |
withKeyValue(java.lang.Object key,
java.lang.Object value) |
JsonObject |
withKeyValue(java.lang.String key,
java.lang.Object value) |
JsonObject |
withTokener(Tokener x)
Tokener to init the JsonObject
|
JsonObject |
withValue(java.lang.String... values)
Set the value to Tokener or pairs of values
|
add, add, containsKey, containsValue, copyEntity, entrySet, get, getBoolean, getDouble, getInt, getKey, getKeyByIndex, getString, getString, getValue, getValueByIndex, increment, indexOfValue, iterator, keyIterator, keySet, put, putAll, remove, setValueItem, values, with, withAll, withList, withList, withMapaddFlag, addHashItem, addKey, addKeyValue, checkValue, clear, comparator, contains, containsAll, fireProperty, first, flag, get, getByIndex, getLastPositionKey, getPositionKey, getPositionValue, getSignalFlag, getValueItem, hashKey, hasKey, hasKeyAndPos, indexOf, init, init, init, isAllowDuplicate, isAllowEmptyValue, isCaseSensitive, isComparator, isEmpty, isReadOnly, isVisible, last, lastindexOf, move, pack, removeAll, removeByObject, retainAll, setValue, size, subList, toArray, toArray, withAllowDuplicate, withAllowEmptyValue, withCaseSensitive, withFlag, without, withVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisVisible, withVisiblecontainsKey, get, getBoolean, getDouble, getInt, getStringpublic JsonArray getJsonArray(java.lang.String key)
key - A key string.public JsonObject getJsonObject(java.lang.String key)
key - A key string.java.lang.RuntimeException - if the key is not found or if the value is not a JsonObject.public long getLong(java.lang.String key)
getLong in class SimpleKeyValueList<java.lang.String,java.lang.Object>key - A key string.java.lang.RuntimeException - if the key is not found or if the value is not a JsonObject.public java.lang.String toString()
Warning: This method assumes that the data structure is acyclical.
public java.lang.String toString(int indentFactor)
Warning: This method assumes that the data structure is acyclical.
toString in interface StringItemindentFactor - The number of spaces to add to each level of indentation.{ (left
brace) and ending with } (right
brace).public java.lang.String toString(int indentFactor,
int indent)
toString in interface StringItempublic JsonObject withValue(java.lang.String... values)
values - a simple String of Value or pairs of key-valuespublic JsonObject withTokener(Tokener x)
x - tokener to add values with the tokenerpublic JsonObject withEntity(SimpleKeyValueList<?,?> entity)
entity - entity to add values with the tokenerpublic BaseItem getNewList(boolean keyValue)
getNewList in interface BaseItemgetNewList in class SimpleKeyValueList<java.lang.String,java.lang.Object>public boolean has(java.lang.String key)
public JsonObject withKeyValue(java.lang.Object key, java.lang.Object value)
withKeyValue in class SimpleKeyValueList<java.lang.String,java.lang.Object>public JsonObject addToList(java.lang.String key, java.lang.Object value)
key - A key string.value - An object to be accumulated under the key.public JsonObject withKeyValue(java.lang.String key, java.lang.Object value)