public static class JSON.Value
JSON.parse(String) returns JSON.Value.
To access the content, use the apply operators:
val json = JSON.parse(...);
val x = json("x");
val y = json("y", "default"); // default
val z = json(["z1", "z2", "z3"]); // first one
If the key is a number, it is interpreted as a JSON Array (or X10 List) type. If the key is a string, it is interpreted as a JSON Object (or X10 Map) type. See the definition below for details.
| Constructor and Description |
|---|
JSON.Value(Any value,
cassia.util.JSON.Reader p,
Int i) |
JSON.Value(Any value) |
| Modifier and Type | Method and Description |
|---|---|
<T> JSON.Value |
any(Rail<T> s)
Get the value associated with the key first matched if any such exists.
|
List<JSON.Value> |
asList() |
Map<String,JSON.Value> |
asMap() |
JSON.Value |
clone() |
Boolean |
equals(Any that)
Perform a String-vs-String equality test.
|
<T> JSON.Value |
get(T s)
Get the value associated with the key if exists.
|
<T> JSON.Value |
get(Rail<T> s)
Get the final value associated with all the keys in the list.
|
protected String |
getExInfo()
Get an error message with the JSON text around.
|
<T> JSON.Value |
getOrElse(T s,
String orElse)
Get the value associated with the key if exists;
Otherwise return
JSON.parse(orElse). |
<T> Boolean |
has(T s)
Test if it has the key
s. |
Boolean |
isList() |
Boolean |
isMap() |
Boolean |
isNull() |
<T> JSON.Value |
operator()(T key)
Get the value associated with the key if exists.
|
<T> JSON.Value |
operator()(Rail<T> keys)
Get the value associated with the key first matched if any such exists.
|
<T> JSON.Value |
operator()(T key,
String orElse)
Get the value associated with the key if exists;
Otherwise returns
JSON.parse(orElse). |
<T> JSON.Value |
operator()=(T key,
JSON.Value v) |
<T> JSON.Value |
operator()=(T key,
Any v) |
<T> JSON.Value |
put(T s,
JSON.Value v) |
<T> JSON.Value |
put(T s,
Any v) |
void |
set(Any v) |
Long |
size()
Get the size of this JSON Array or JSON Object (otherwise return 0).
|
Boolean |
toBoolean() |
Double |
toDouble() |
Int |
toInt() |
Long |
toLong() |
String |
toString()
Cast this
JSON.Value to String. |
public JSON.Value(Any value,
cassia.util.JSON.Reader p,
Int i)
public JSON.Value(Any value)
public <T> JSON.Value get(T s)
toString() and then
treated as Long if isList() but as String if isMap().
JSON: {"one": {"two": {"three": 3}}}
X10 : json("one")("two")("three").toLong() // gets 3
s - a keypublic <T> JSON.Value get(Rail<T> s)
JSON: {"one": {"two": {"three": 3}}}
X10 : json(["one", "two", "three"]).toLong() // gets 3
s - a key listpublic <T> JSON.Value getOrElse(T s, String orElse)
JSON.parse(orElse).
JSON: {"one": {"two": {"three": 3}}}
X10 : json("one")("two")("threat", "13").toLong() // gets 13
s - a keyorElse - a JSON text used if s not foundpublic void set(Any v)
public <T> JSON.Value put(T s, JSON.Value v)
public <T> JSON.Value put(T s, Any v)
public <T> Boolean has(T s)
s.s - a keypublic <T> JSON.Value any(Rail<T> s)
JSON: {"one": 1, "TWO": 2, "THREE": 3}
X10 : json(["ONE", "TWO", "THREE"]).toLong() // gets 2
s - a key listpublic Long size()
public <T> JSON.Value operator()(T key)
toString() and then
treated as Long if isList() but as String if isMap().
JSON: {"one": {"two": {"three": 3}}}
X10 : json("one")("two")("three").toLong() // gets 3
key - a keypublic <T> JSON.Value operator()=(T key, JSON.Value v)
public <T> JSON.Value operator()=(T key, Any v)
public <T> JSON.Value operator()(T key, String orElse)
JSON.parse(orElse).
JSON: {"one": {"two": {"three": 3}}}
X10 : json("one")("two")("threat", "13").toLong() // gets 13
key - a keyorElse - a JSON text used if s not foundpublic <T> JSON.Value operator()(Rail<T> keys)
JSON: {"one": 1, "TWO": 2, "THREE": 3}
X10 : json(["ONE", "TWO", "THREE"]).toLong() // gets 2
keys - a key listpublic Boolean isNull()
public Boolean isMap()
public Map<String,JSON.Value> asMap()
public Boolean isList()
public List<JSON.Value> asList()
public Boolean equals(Any that)
equals(), the following
json("x").equals("x")
results in the unintended JSON.Value-vs-String test,
returning always false.that - protected String getExInfo()
public String toString()
JSON.Value to String.
Use JSON.dump() instead.public Boolean toBoolean()
public Int toInt()
public Long toLong()
public Double toDouble()
public JSON.Value clone()