public class JSONObjectUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Base64URL |
getBase64URL(Map<String,Object> o,
String key)
Gets a string member of a JSON object as
Base64URL . |
static boolean |
getBoolean(Map<String,Object> o,
String key)
Gets a boolean member of a JSON object.
|
static double |
getDouble(Map<String,Object> o,
String key)
Gets a number member of a JSON object as
double . |
static float |
getFloat(Map<String,Object> o,
String key)
Gets a number member of a JSON object
float . |
static int |
getInt(Map<String,Object> o,
String key)
Gets an number member of a JSON object as
int . |
static List<Object> |
getJSONArray(Map<String,Object> o,
String key)
Gets a JSON array member of a JSON object.
|
static Map<String,Object> |
getJSONObject(Map<String,Object> o,
String key)
Gets a JSON object member of a JSON object.
|
static long |
getLong(Map<String,Object> o,
String key)
Gets a number member of a JSON object as
long . |
static String |
getString(Map<String,Object> o,
String key)
Gets a string member of a JSON object.
|
static String[] |
getStringArray(Map<String,Object> o,
String key)
Gets a string array member of a JSON object.
|
static List<String> |
getStringList(Map<String,Object> o,
String key)
Gets a string list member of a JSON object
|
static URI |
getURI(Map<String,Object> o,
String key)
Gets a string member of a JSON object as
java.net.URI . |
static Map<String,Object> |
newJSONObject()
Creates a new JSON object (unordered).
|
static Map<String,Object> |
parse(String s)
Parses a JSON object.
|
static Map<String,Object> |
parseJSONObject(String s)
Deprecated.
|
static String |
toJSONString(Map<String,?> o)
Serialises the specified map to a JSON object using the entity
mapping specified in
parse(String) . |
public static Map<String,Object> parse(String s) throws ParseException
Specific JSON to Java entity mapping (as per JSON Smart):
java.lang.Boolean
.
java.lang.Number
.
long
.
double
.
java.lang.String
.
java.util.List<Object>
.
java.util.Map<String,Object>
.
s
- The JSON object string to parse. Must not be null
.ParseException
- If the string cannot be parsed to a valid JSON
object.@Deprecated public static Map<String,Object> parseJSONObject(String s) throws ParseException
parse(String)
instead.s
- The JSON object string to parse. Must not be null
.ParseException
- If the string cannot be parsed to a valid JSON
object.public static boolean getBoolean(Map<String,Object> 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 member is missing, the value is
null
or not of the expected type.public static int getInt(Map<String,Object> 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 member is missing, the value is
null
or not of the expected type.public static long getLong(Map<String,Object> 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 member is missing, the value is
null
or not of the expected type.public static float getFloat(Map<String,Object> o, String key) throws ParseException
float
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the member is missing, the value is
null
or not of the expected type.public static double getDouble(Map<String,Object> o, String key) throws ParseException
double
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the member is missing, the value is
null
or not of the expected type.public static String getString(Map<String,Object> o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static URI getURI(Map<String,Object> 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
.null
.ParseException
- If the value is not of the expected type.public static List<Object> getJSONArray(Map<String,Object> o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static String[] getStringArray(Map<String,Object> o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static List<String> getStringList(Map<String,Object> o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static Map<String,Object> getJSONObject(Map<String,Object> o, String key) throws ParseException
o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static Base64URL getBase64URL(Map<String,Object> o, String key) throws ParseException
Base64URL
.o
- The JSON object. Must not be null
.key
- The JSON object member key. Must not be null
.null
.ParseException
- If the value is not of the expected type.public static String toJSONString(Map<String,?> o)
parse(String)
.o
- The map. Must not be null
.public static Map<String,Object> newJSONObject()
Copyright © 2021 Connect2id Ltd.. All rights reserved.