public class JSONObjectUtils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
containsKey(net.minidev.json.JSONObject jsonObject,
String key)
Returns
true if the JSON object is defined and contains the
specified key. |
static boolean |
getBoolean(net.minidev.json.JSONObject o,
String key)
Gets a boolean member of a JSON object.
|
static double |
getDouble(net.minidev.json.JSONObject o,
String key)
Gets a number member of a JSON object as
double . |
static javax.mail.internet.InternetAddress |
getEmail(net.minidev.json.JSONObject o,
String key)
Deprecated.
|
static <T extends Enum<T>> |
getEnum(net.minidev.json.JSONObject o,
String key,
Class<T> enumClass)
Gets a string member of a JSON object as an enumerated object.
|
static float |
getFloat(net.minidev.json.JSONObject o,
String key)
Gets a number member of a JSON object
float . |
static <T> T |
getGeneric(net.minidev.json.JSONObject o,
String key,
Class<T> clazz)
Gets a generic member of a JSON object.
|
static int |
getInt(net.minidev.json.JSONObject o,
String key)
Gets an number member of a JSON object as
int . |
static net.minidev.json.JSONArray |
getJSONArray(net.minidev.json.JSONObject o,
String key)
Gets a JSON array member of a JSON object.
|
static net.minidev.json.JSONObject |
getJSONObject(net.minidev.json.JSONObject o,
String key)
Gets a JSON object member of a JSON object.
|
static List<Object> |
getList(net.minidev.json.JSONObject o,
String key)
Gets a list member of a JSON object.
|
static long |
getLong(net.minidev.json.JSONObject o,
String key)
Gets a number member of a JSON object as
long . |
static Number |
getNumber(net.minidev.json.JSONObject o,
String key)
Gets a number member of a JSON object as
java.lang.Number . |
static String |
getString(net.minidev.json.JSONObject o,
String key)
Gets a string member of a JSON object.
|
static String[] |
getStringArray(net.minidev.json.JSONObject o,
String key)
Gets a string array member of a JSON object.
|
static List<String> |
getStringList(net.minidev.json.JSONObject o,
String key)
Gets a string list member of a JSON object.
|
static Set<String> |
getStringSet(net.minidev.json.JSONObject o,
String key)
Gets a string array member of a JSON object as a string set.
|
static URI |
getURI(net.minidev.json.JSONObject o,
String key)
Gets a string member of a JSON object as
java.net.URI . |
static URL |
getURL(net.minidev.json.JSONObject o,
String key)
Gets a string member of a JSON object as
java.net.URL . |
static net.minidev.json.JSONObject |
parse(String s)
Parses a JSON object.
|
static net.minidev.json.JSONObject |
parseJSONObject(String s)
Deprecated.
|
public static boolean containsKey(net.minidev.json.JSONObject jsonObject, String key)
true
if the JSON object is defined and contains the
specified key.jsonObject
- The JSON object to check. May be null
.key
- The key to check. Must not be null
.true
if the JSON object is defined and contains the
specified key, else false
.public static net.minidev.json.JSONObject parse(String s) throws ParseException
Specific JSON to Java entity mapping (as per JSON Simple):
java.lang.Number
.
long
.
double
.
s
- The JSON object string to parse. Must not be null
.ParseException
- If the string cannot be parsed to a JSON
object.@Deprecated public static net.minidev.json.JSONObject parseJSONObject(String s) throws ParseException
parse(String)
instead.ParseException
public static <T> T getGeneric(net.minidev.json.JSONObject o, String key, Class<T> clazz) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.clazz
- The expected class of the JSON object member value. Must
not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static boolean getBoolean(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static int getInt(net.minidev.json.JSONObject o, String key) throws ParseException
int
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static long getLong(net.minidev.json.JSONObject o, String key) throws ParseException
long
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static float getFloat(net.minidev.json.JSONObject o, String key) throws ParseException
float
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static double getDouble(net.minidev.json.JSONObject o, String key) throws ParseException
double
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static Number getNumber(net.minidev.json.JSONObject o, String key) throws ParseException
java.lang.Number
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static String getString(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static <T extends Enum<T>> T getEnum(net.minidev.json.JSONObject o, String key, Class<T> enumClass) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be
null
.enumClass
- The enumeration class. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static URI getURI(net.minidev.json.JSONObject o, String key) throws ParseException
java.net.URI
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static URL getURL(net.minidev.json.JSONObject o, String key) throws ParseException
java.net.URL
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.@Deprecated public static javax.mail.internet.InternetAddress getEmail(net.minidev.json.JSONObject o, String key) throws ParseException
javax.mail.internet.InternetAddress
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static net.minidev.json.JSONArray getJSONArray(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static List<Object> getList(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static String[] getStringArray(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static List<String> getStringList(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static Set<String> getStringSet(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.public static net.minidev.json.JSONObject getJSONObject(net.minidev.json.JSONObject o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.ParseException
- If the value is missing, null
or not
of the expected type.Copyright © 2017 Connect2id Ltd.. All rights reserved.