public class JSONObjectHelper
extends java.lang.Object
Constructor and Description |
---|
JSONObjectHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
addAll(JSONArray destinationArray,
JSONArray array)
Add all elements from array to destinationArray
|
static JSONObject |
makeJSONObject(java.lang.String key,
java.lang.Object value) |
static java.lang.Object |
opt(JSONArray arr,
int index)
Return null if arr doesn't have value at index or the value is null
JSONArray.opt(index) return the JSONObject.NULL if array has null at index and null if array doesn't have value at index
|
static java.lang.Object |
opt(JSONObject obj,
java.lang.String key)
Return null if object doesn't have key or if obj has null for key
JSONObject.opt(key) return the JSONObject.NULL if object has null for key and null if object doesn't have key
|
static java.lang.String |
optString(JSONObject obj,
java.lang.String key)
Return null if obj doesn't have key or if obj has null for key
JSONObject.optString(key, fallback) returns the string "null" if object has null for key and null if object doesn't have key
|
static java.lang.String |
optString(JSONObject obj,
java.lang.String key,
java.lang.String fallback)
Return the fallback if obj doesn't have key or if obj has null for key
JSONObject.optString(key, fallback) returns the string "null" if object has null for key and null is object doesn't have key
|
static java.lang.String[] |
optStringArray(JSONObject obj,
java.lang.String key)
Return null if obj doesn't have key or if obj has null for key - and return value as a String[] otherwise
|
static <T> java.util.List<T> |
pluck(JSONArray jsonArray,
java.lang.String key)
Given a JSONArray of JSONObject, return list made of values for key
|
static <T> java.util.List<T> |
pluck(JSONObject[] jsonObjects,
java.lang.String key)
Given an array of JSONObject, return list made of values for key
|
static <T> java.util.List<T> |
toList(JSONArray jsonArray)
Convert JSONArray of T into list of T
|
static <T> java.util.Map<java.lang.String,T> |
toMap(JSONObject jsonObject)
Convert JSONObject into Map of String to T
|
public static java.lang.Object opt(JSONObject obj, java.lang.String key)
public static java.lang.Object opt(JSONArray arr, int index)
public static java.lang.String[] optStringArray(JSONObject obj, java.lang.String key) throws JSONException
obj
- key
- JSONException
public static java.lang.String optString(JSONObject obj, java.lang.String key) throws JSONException
obj
- key
- JSONException
public static java.lang.String optString(JSONObject obj, java.lang.String key, java.lang.String fallback) throws JSONException
obj
- key
- fallback
- JSONException
public static <T> java.util.List<T> toList(JSONArray jsonArray) throws JSONException
T
- jsonArray
- JSONException
public static <T> java.util.Map<java.lang.String,T> toMap(JSONObject jsonObject) throws JSONException
T
- jsonObject
- JSONException
public static <T> java.util.List<T> pluck(JSONArray jsonArray, java.lang.String key) throws JSONException
T
- jsonArray
- key
- JSONException
public static <T> java.util.List<T> pluck(JSONObject[] jsonObjects, java.lang.String key) throws JSONException
T
- jsonObjects
- key
- JSONException
public static JSONObject makeJSONObject(java.lang.String key, java.lang.Object value) throws JSONException
key
- value
- JSONException
public static void addAll(JSONArray destinationArray, JSONArray array) throws JSONException
destinationArray
- array
- JSONException