public class JsonInput
extends java.lang.Object
Constructor and Description |
---|
JsonInput() |
Modifier and Type | Method and Description |
---|---|
static org.json.JSONArray |
getArrayNotNull(org.json.JSONObject obj,
java.lang.String field)
Returns a json array as "not-null" value.
|
static org.json.JSONArray |
getArrayOrNull(org.json.JSONObject obj,
java.lang.String field)
Returns a json array as "not-null" value.
|
static java.util.Date |
getDateOrNull(org.json.JSONObject obj,
java.lang.String field,
java.text.SimpleDateFormat dateFormat)
Fetch a date or null.
|
static java.lang.Float |
getFloatOrNull(org.json.JSONObject obj,
java.lang.String field)
Fetches an optional float from an object.
|
static int |
getInt(org.json.JSONObject obj,
java.lang.String field)
Fetches an int from an object.
|
static int |
getInt(org.json.JSONObject obj,
java.lang.String field,
int deflt)
Fetches an int from an object.
|
static java.lang.Integer |
getIntOrNull(org.json.JSONObject obj,
java.lang.String field)
Fetches an optional int from an object.
|
static <T> java.util.List<T> |
getListNotNull(org.json.JSONObject obj,
java.lang.String field,
JsonObjectParser<T> parser)
Parses required item list.
|
static <T> java.util.List<T> |
getListOrEmpty(org.json.JSONObject obj,
java.lang.String field,
JsonObjectParser<T> parser)
Parses optional item list.
|
static <T> java.util.List<T> |
getListOrNull(org.json.JSONObject obj,
java.lang.String field,
JsonObjectParser<T> parser)
Parses optional item list.
|
static long |
getLong(org.json.JSONObject obj,
java.lang.String field)
Fetches a long from an object.
|
static java.lang.Long |
getLongOrNull(org.json.JSONObject obj,
java.lang.String field)
Fetches an optional long from an object.
|
static org.json.JSONObject |
getObjectNotNull(org.json.JSONObject obj,
java.lang.String field)
Returns a json object field for a specified object.
|
static org.json.JSONObject |
getObjectOrNull(org.json.JSONObject obj,
java.lang.String field)
Returns a json object field for a specified object.
|
static <T> T |
getObjectOrNull(org.json.JSONObject obj,
java.lang.String field,
JsonObjectParser<T> parser)
Retreive optional object.
|
static boolean |
getOptionalBool(org.json.JSONObject obj,
java.lang.String field)
Returns an optional "boolean" field value.
|
static java.lang.String |
getStringNotNull(org.json.JSONObject obj,
java.lang.String field)
Fetches a string from an object.
|
static java.lang.String |
getStringOrEmpty(org.json.JSONObject obj,
java.lang.String field)
Fetches an optional string from an object.
|
static java.lang.String |
getStringOrNull(org.json.JSONObject obj,
java.lang.String field)
Fetches an optional string from an object.
|
public static <T> java.util.List<T> getListNotNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.org.json.JSONException
- if format is invalid.public static <T> java.util.List<T> getListOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.org.json.JSONException
- if format is invalid.public static <T> java.util.List<T> getListOrEmpty(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.org.json.JSONException
- if format is invalid.public static java.util.Date getDateOrNull(org.json.JSONObject obj, java.lang.String field, java.text.SimpleDateFormat dateFormat) throws org.json.JSONException
obj
- object to get.field
- field to use.dateFormat
- field date format.org.json.JSONException
- if error occurs.public static java.lang.String getStringOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not validpublic static boolean getOptionalBool(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
null
, this method returns false
.obj
- object to get a field from.field
- field to get a value for.org.json.JSONException
- if input is not valid (field value is not boolean).public static java.lang.String getStringOrEmpty(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not validpublic static java.lang.String getStringNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static int getInt(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static int getInt(org.json.JSONObject obj, java.lang.String field, int deflt) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.deflt
- default value.org.json.JSONException
- if value is not valid, not exists, etc...public static java.lang.Integer getIntOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static long getLong(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static java.lang.Long getLongOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static java.lang.Float getFloatOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- field to get a value from.org.json.JSONException
- if value is not valid, not exists, etc...public static <T> T getObjectOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
obj
- object to parse.field
- field part.parser
- parset ojbect.org.json.JSONException
- if value is not valid.public static org.json.JSONArray getArrayOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a value from.field
- field to get a value from.org.json.JSONException
public static org.json.JSONArray getArrayNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a value from.field
- field to get a value from.org.json.JSONException
public static org.json.JSONObject getObjectNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- returned field.org.json.JSONException
- if target field is not an object.public static org.json.JSONObject getObjectOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
obj
- object to get a field from.field
- returned field.org.json.JSONException
- if target field is not an object.