public class JsonObject extends SimpleKeyValueList<java.lang.String,java.lang.Object> implements 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).| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
END |
static java.lang.String |
START |
ALLOWDUPLICATE, ALLOWEMPTYVALUE, BIDI, CASESENSITIVE, flag, MAP, READONLY, REMOVED, 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.
|
static JsonObject |
create(java.lang.String value) |
BaseItem |
getChild(java.lang.String label,
boolean recursiv) |
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)
check if Entity has the Key
|
protected java.lang.String |
parseItem(EntityStringConverter converter) |
JsonObject |
setType(java.lang.String type) |
boolean |
setValueItem(java.lang.Object value) |
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.
|
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) |
Entity |
without(java.lang.String key) |
JsonObject |
withTokener(Tokener x)
Tokener to init the JsonObject
|
JsonObject |
withValue(Buffer values)
Set the value to Tokener or pairs of values
|
JsonObject |
withValue(java.lang.String... values)
Set the value to Tokener or pairs of values
|
add, add, addToKeyValue, containsKey, containsValue, copyEntity, entrySet, get, getBoolean, getDouble, getInt, getKey, getKeyByIndex, getPositionValue, getString, getString, getValueByIndex, increment, indexOfValue, iterator, keyIterator, keySet, put, putAll, remove, removePos, setValue, setValueItem, values, valuesArrayIntern, with, with, withKeyValueString, withList, withMap, withoutaddHashItem, addKeyValue, checkValue, clear, comparator, contains, containsAll, fireProperty, first, flag, get, getByIndex, getPositionKey, getValue, hashKey, hasKeyAndPos, indexOf, init, init, init, isAllowDuplicate, isAllowEmptyValue, isCaseSensitive, isComparator, isEmpty, isReadOnly, isVisible, last, lastIndexOf, move, pack, removeAll, removeByObject, reset, retainAll, setAllowEmptyValue, setFlag, setValue, size, subList, toArray, toArray, toString, withAllowDuplicate, withAllowEmptyValue, withCaseSensitive, withFlag, withSize, withVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetKeyByIndex, getString, getValue, put, setAllowEmptyValue, sizepublic static final java.lang.String START
public static final java.lang.String END
public 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.
toString in interface BaseItemtoString in class AbstractArray<java.lang.String>{ (left
brace) and ending with } (right
brace).public java.lang.String toString(int indentFactor)
Warning: This method assumes that the data structure is acyclical.
protected java.lang.String parseItem(EntityStringConverter converter)
parseItem in class AbstractArray<java.lang.String>public JsonObject withValue(java.lang.String... values)
values - a simple String of Value or pairs of key-valuespublic JsonObject withValue(Buffer values)
public 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)
Entitypublic 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)
public static JsonObject create(java.lang.String value)
public boolean setValueItem(java.lang.Object value)
setValueItem in interface Entitypublic BaseItem getChild(java.lang.String label, boolean recursiv)
public JsonObject setType(java.lang.String type)