public class JsonUtils
extends org.json.JSONObject
| Constructor and Description |
|---|
JsonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areJsonObjectsEqual(org.json.JSONObject target,
org.json.JSONObject source)
If both null, returns true.
|
static <T> org.json.JSONArray |
constructJsonArray(java.util.Collection<? extends IPutIntoJson<T>> inputList) |
static <T> org.json.JSONArray |
constructJsonArray(T[] inputArray)
Creates a new
JSONArray containing the contents of the input array. |
static java.util.Map<java.lang.String,java.lang.String> |
convertJSONObjectToMap(org.json.JSONObject object)
Converts a
JSONObject to a Map |
static java.util.List<java.lang.String> |
convertStringJsonArrayToList(org.json.JSONArray jsonArray)
Converts the contents of the
JSONArray to an List of Strings. |
static java.lang.Integer |
getColorIntegerOrNull(org.json.JSONObject object,
java.lang.String key) |
static <TargetEnum extends java.lang.Enum<TargetEnum>> |
getEnum(org.json.JSONObject object,
java.lang.String key,
java.lang.Class<TargetEnum> targetEnumClass) |
static java.lang.String |
getOptionalString(org.json.JSONObject object,
java.lang.String key)
Returns the string value for key, or
null if the key is not mapped in the object.
|
static java.lang.String |
getPrettyPrintedString(org.json.JSONArray jsonArray)
Returns the
JSONArray.toString(int) result if possible. |
static java.lang.String |
getPrettyPrintedString(org.json.JSONObject jsonObject)
Returns the
JSONObject.toString(int) result if possible. |
static org.json.JSONObject |
mergeJsonObjects(org.json.JSONObject oldJson,
org.json.JSONObject newJson)
Merges key-values from oldJson and newJson into a new JSONObject.
|
static <TargetEnum extends java.lang.Enum<TargetEnum>> |
optEnum(org.json.JSONObject object,
java.lang.String key,
java.lang.Class<TargetEnum> targetEnumClass,
TargetEnum defaultEnum) |
static android.os.Bundle |
parseJsonObjectIntoBundle(java.lang.String jsonStringDictionary)
Parses the JSON into a bundle.
|
accumulate, get, getBoolean, getDouble, getInt, getJSONArray, getJSONObject, getLong, getString, has, isNull, keys, length, names, numberToString, opt, optBoolean, optBoolean, optDouble, optDouble, optInt, optInt, optJSONArray, optJSONObject, optLong, optLong, optString, optString, put, put, put, put, put, putOpt, quote, remove, toJSONArray, toString, toString, wrappublic static <TargetEnum extends java.lang.Enum<TargetEnum>> TargetEnum getEnum(org.json.JSONObject object,
java.lang.String key,
java.lang.Class<TargetEnum> targetEnumClass)
throws org.json.JSONException
org.json.JSONExceptionpublic static <TargetEnum extends java.lang.Enum<TargetEnum>> TargetEnum optEnum(org.json.JSONObject object,
java.lang.String key,
java.lang.Class<TargetEnum> targetEnumClass,
TargetEnum defaultEnum)
public static <T> org.json.JSONArray constructJsonArray(java.util.Collection<? extends IPutIntoJson<T>> inputList)
public static <T> org.json.JSONArray constructJsonArray(T[] inputArray)
JSONArray containing the contents of the input array.inputArray - the input array. When null, returns an empty JSONArraypublic static java.lang.String getOptionalString(org.json.JSONObject object,
java.lang.String key)
public static java.util.Map<java.lang.String,java.lang.String> convertJSONObjectToMap(org.json.JSONObject object)
throws org.json.JSONException
JSONObject to a Mapobject - The JSONObject to convert.org.json.JSONExceptionpublic static java.util.List<java.lang.String> convertStringJsonArrayToList(org.json.JSONArray jsonArray)
JSONArray to an List of Strings.public static org.json.JSONObject mergeJsonObjects(org.json.JSONObject oldJson,
org.json.JSONObject newJson)
public static java.lang.String getPrettyPrintedString(org.json.JSONObject jsonObject)
JSONObject.toString(int) result if possible.
Returns an empty string if the input JSONObject is null or
on any thrown Throwable.public static java.lang.String getPrettyPrintedString(org.json.JSONArray jsonArray)
JSONArray.toString(int) result if possible.
Returns an empty string if the input JSONArray is null or
on any thrown Throwable.public static java.lang.Integer getColorIntegerOrNull(org.json.JSONObject object,
java.lang.String key)
public static boolean areJsonObjectsEqual(org.json.JSONObject target,
org.json.JSONObject source)
If exactly one is null, returns false.
If the number of keys differs, returns false.
If a key in target is missing from source, returns false.
If a key/value in target is a JSONObject, then that corresponding
key/value JSONObject in source must equal according to this
method, else returns false.
If a key/value in target does not return true for
Object.equals(Object) for that corresponding
key/value in source, then returns false.
Otherwise return true.
Note that JSONArray will also
use Object.equals(Object). If this functionality is not
desired, add a corresponding case for JSONArray. Currently,
the return value is undefined here.
public static android.os.Bundle parseJsonObjectIntoBundle(java.lang.String jsonStringDictionary)