Package playn.core
Interface Json.Object
- Enclosing interface:
Json
public static interface Json.Object
Represents a parsed JSON object as a simple
string->value
map.-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String key) Returns true if this object contains a value at the specified key, false if not.Gets the array value at the given key, ornull
if there is no value at this key.<T> Json.TypedArray<T>
Gets an array at the given key that assumes its values are of the given json type, ornull
if there is no value at this key.<T> Json.TypedArray<T>
getArray
(String key, Class<T> jsonType, Json.TypedArray<T> dflt) Gets an array at the given key that assumes its values are of the given json type, or the default if there is no value at this key.getArray
(String key, Json.Array dflt) Gets the array value at the given key, or the default if there is no value at this key.boolean
getBoolean
(String key) Gets the boolean value at the given key, orfalse
if there is no value at this key.boolean
getBoolean
(String key, boolean dflt) Gets the boolean value at the given key, or the default if there is no value at this key.double
Gets the double value at the given key, or0
if there is no value at this key.double
Gets the double value at the given key, or the default if there is no value at this key.int
Gets the integer value at the given key, or0
if there is no value at this key.int
Gets the integer value at the given key, or the default if there is no value at this key.long
Gets the long value at the given key, or0
if there is no value at this key.long
Gets the long value at the given key, or the default if there is no value at this key.float
Gets the float value at the given key, or0
if there is no value at this key.float
Gets the float value at the given key, or the default if there is no value at this key.Gets the object value at the given key, ornull
if there is no value at this key.getObject
(String key, Json.Object dflt) Gets the object value at the given key, or the default if there is no value at this key.Gets the string value at the given key, ornull
if there is no value at this key.Gets the string value at the given key, or the default if there is no value at this key.boolean
Returnstrue
if the value at the given key is an array.boolean
Returnstrue
if the value at the given key is a boolean.boolean
Returnstrue
if the value at the given key is null or does not exist.boolean
Returnstrue
if the value at the given key is a number.boolean
Returnstrue
if the value at the given key is an object.boolean
Returnstrue
if the value at the given key is a string.keys()
Gets a snapshot of the current set of keys for this JSON object.Inserts a JSON null, object, array or string value at the given key.Removes a JSON value at the given key.<T extends playn.core.json.JsonSink<T>>
playn.core.json.JsonSink<T>write
(playn.core.json.JsonSink<T> sink) Writes this object to aJsonSink
.
-
Method Details
-
getBoolean
Gets the boolean value at the given key, orfalse
if there is no value at this key. -
getBoolean
Gets the boolean value at the given key, or the default if there is no value at this key. -
getNumber
Gets the float value at the given key, or0
if there is no value at this key. -
getNumber
Gets the float value at the given key, or the default if there is no value at this key. -
getDouble
Gets the double value at the given key, or0
if there is no value at this key. -
getDouble
Gets the double value at the given key, or the default if there is no value at this key. -
getInt
Gets the integer value at the given key, or0
if there is no value at this key. -
getInt
Gets the integer value at the given key, or the default if there is no value at this key. -
getLong
Gets the long value at the given key, or0
if there is no value at this key. NOTE: this is not accurate on the HTML backend as all numbers are represented as doubles, which cannot represent all possible long values. This is included for projects that use only the other backends and need long values. -
getLong
Gets the long value at the given key, or the default if there is no value at this key. NOTE: this is not accurate on the HTML backend as all numbers are represented as doubles, which cannot represent all possible long values. This is included for projects that use only the other backends and need long values. -
getString
Gets the string value at the given key, ornull
if there is no value at this key. -
getString
Gets the string value at the given key, or the default if there is no value at this key. -
getObject
Gets the object value at the given key, ornull
if there is no value at this key. -
getObject
Gets the object value at the given key, or the default if there is no value at this key. -
getArray
Gets the array value at the given key, ornull
if there is no value at this key. -
getArray
Gets the array value at the given key, or the default if there is no value at this key. -
getArray
Gets an array at the given key that assumes its values are of the given json type, ornull
if there is no value at this key.- Parameters:
jsonType
- one of Json.Object, Json.Array, Boolean, Integer, Float, Double, or String- Throws:
IllegalArgumentException
- if jsonType is of an invalid type.
-
getArray
Gets an array at the given key that assumes its values are of the given json type, or the default if there is no value at this key.- Parameters:
jsonType
- one of Json.Object, Json.Array, Boolean, Integer, Float, Double, or Stringdflt
- An existing typed array- Throws:
IllegalArgumentException
- if jsonType is of an invalid type.
-
containsKey
Returns true if this object contains a value at the specified key, false if not. -
keys
Json.TypedArray<String> keys()Gets a snapshot of the current set of keys for this JSON object. Modifications to the object will not be reflected in this set of keys. -
isArray
Returnstrue
if the value at the given key is an array. -
isBoolean
Returnstrue
if the value at the given key is a boolean. -
isNull
Returnstrue
if the value at the given key is null or does not exist. -
isNumber
Returnstrue
if the value at the given key is a number. -
isString
Returnstrue
if the value at the given key is a string. -
isObject
Returnstrue
if the value at the given key is an object. -
put
Inserts a JSON null, object, array or string value at the given key.- Returns:
- a reference to this, allowing the calls to be chained together.
-
remove
Removes a JSON value at the given key.- Returns:
- a reference to this, allowing the calls to be chained together.
-
write
<T extends playn.core.json.JsonSink<T>> playn.core.json.JsonSink<T> write(playn.core.json.JsonSink<T> sink) Writes this object to aJsonSink
.
-