public final class JSONUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static @NotNull org.json.JSONArray |
asJSONArray(@NotNull java.lang.Object object)
Convert the given
object into a json array. |
static @NotNull org.json.JSONObject |
asJSONObject(@NotNull java.lang.Object object)
Convert the given
object into a json object. |
static @NotNull java.lang.Object |
get(@NotNull java.lang.Object object,
@NotNull java.util.List<java.lang.String> keys)
Assuming the given
object is a JSONArray or a JSONObject,
get the value stored at the given nesting keys. |
static @NotNull java.lang.Object |
get(@NotNull java.lang.Object object,
@NotNull java.lang.String keys)
Delegates to
get(Object, List) with the keys being the result of invoking
keys(String) with the given keys. |
static @NotNull java.util.List<java.lang.String> |
keys(@NotNull java.lang.String keys)
Convert the given string into a nesting keys list.
|
static @NotNull java.lang.Object |
put(@NotNull java.lang.Object object,
@NotNull java.util.List<java.lang.String> keys,
@NotNull java.lang.Object value)
Assuming the given
object is a JSONArray or a JSONObject,
put the given value at given nesting keys. |
static @NotNull java.lang.Object |
put(@NotNull java.lang.Object object,
@NotNull java.lang.String keys,
@NotNull java.lang.Object value)
Delegates to
put(Object, List, Object) with the keys being the result of
invoking keys(String) with the given keys. |
@NotNull
@Contract(pure=true)
public static @NotNull org.json.JSONArray asJSONArray(@NotNull
@NotNull java.lang.Object object)
object into a json array.object - the object.object.java.lang.NullPointerException - if the given object is null.@NotNull
@Contract(pure=true)
public static @NotNull org.json.JSONObject asJSONObject(@NotNull
@NotNull java.lang.Object object)
object into a json object.object - the object.object.java.lang.NullPointerException - if the given object is null.@NotNull
@Contract(pure=true)
public static @NotNull java.lang.Object get(@NotNull
@NotNull java.lang.Object object,
@NotNull
@NotNull java.util.List<java.lang.String> keys)
object is a JSONArray or a JSONObject,
get the value stored at the given nesting keys. If the given object
is not a JSONArray nor a JSONObject or a node in the middle is not
of these types, an empty string will be returned.object - the object to get from.keys - the nesting keys to get the value from.keys in the given object.java.lang.NullPointerException - if the given object or keys is null.@NotNull
@Contract(pure=true)
public static @NotNull java.lang.Object get(@NotNull
@NotNull java.lang.Object object,
@NotNull
@NotNull java.lang.String keys)
get(Object, List) with the keys being the result of invoking
keys(String) with the given keys.object - the object to get from.keys - the source of the keys.keys in the given object.java.lang.NullPointerException - if the given object or keys is null.@NotNull
@Contract(pure=true)
public static @NotNull java.util.List<java.lang.String> keys(@NotNull
@NotNull java.lang.String keys)
keys - the source.java.lang.NullPointerException - if the given keys is null.@NotNull
@Contract(mutates="param")
public static @NotNull java.lang.Object put(@NotNull
@NotNull java.lang.Object object,
@NotNull
@NotNull java.util.List<java.lang.String> keys,
@NotNull
@NotNull java.lang.Object value)
object is a JSONArray or a JSONObject,
put the given value at given nesting keys.object - the object to put to.keys - the nesting keys.value - the value to be put.object if the value can be put, or a replacement object.java.lang.NullPointerException - if the given object or keys or value is null.@NotNull
@Contract(mutates="param")
public static @NotNull java.lang.Object put(@NotNull
@NotNull java.lang.Object object,
@NotNull
@NotNull java.lang.String keys,
@NotNull
@NotNull java.lang.Object value)
put(Object, List, Object) with the keys being the result of
invoking keys(String) with the given keys.object - the object to put to.keys - the source of the nesting keys.value - the value to be put.object if the value can be put, or a replacement object.java.lang.NullPointerException - if the given object or keys or value is null.