public class ZSONObject extends Object
Based on the standard JSON data structure, this class encapsulates a series of read and write methods for different
data types, for example, primitive data types like int and float as well as some custom data types.
It also provides methods for conversion between strings and objects. With these methods, you can process JSON
structured data easily.
| 构造器 | 说明 |
|---|---|
ZSONObject() |
Default constructor used to create a
ZSONObject instance. |
ZSONObject(Map<String,Object> map) |
A constructor used to create a
ZSONObject object based on a specified map. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static ZSONObject |
classToZSON(Object object) |
Converts a specified class object into a
ZSONObject. |
void |
clear() |
Clears the map of the entire
ZSONObject. |
boolean |
containsKey(Object key) |
Checks whether the map of this
ZSONObject contains an object matching the specified key. |
boolean |
containsValue(Object value) |
Checks whether the map of this
ZSONObject contains a value object. |
Set<Map.Entry<String,Object>> |
entrySet() |
Obtains the
entrySet in the map of this ZSONObject. |
Object |
get(Object key) |
Obtains the object matching the specified key in the map of this
ZSONObject. |
BigDecimal |
getBigDecimal(String key) |
Obtains the
BigDecimal object matching the specified key in the map of this ZSONObject. |
BigInteger |
getBigInteger(String key) |
Obtains the
BigInteger object matching the specified key in the map of this ZSONObject. |
Boolean |
getBoolean(String key) |
Obtains the
boolean value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Boolean object. |
boolean |
getBooleanValue(String key) |
Obtains the
boolean value matching the specified key in the map of this ZSONObject. |
Byte |
getByte(String key) |
Obtains the
byte value matching the specified key in the map of this ZSONObject and automatically
converts the value into a Byte object. |
byte[] |
getBytes(String key) |
Obtains the
byte array matching the specified key in the map of this ZSONObject. |
byte |
getByteValue(String key) |
Obtains the
byte value matching the specified key in the map of this ZSONObject. |
Date |
getDate(String key) |
Obtains the
Date object matching the specified key in the map of this ZSONObject. |
Double |
getDouble(String key) |
Obtains the
double value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Double object. |
double |
getDoubleValue(String key) |
Obtains the
double value matching the specified key in the map of this ZSONObject. |
Float |
getFloat(String key) |
Obtains the
float value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Float object. |
float |
getFloatValue(String key) |
Obtains the
float value matching the specified key in the map of this ZSONObject. |
Integer |
getInteger(String key) |
Obtains the
int value matching the specified key in the map of this ZSONObject and automatically
converts the value into an Integer object. |
int |
getIntValue(String key) |
Obtains the
int value matching the specified key in the map of this ZSONObject. |
Long |
getLong(String key) |
Obtains the
long value matching the specified key in the map of this ZSONObject and automatically
converts the value into a Long object. |
long |
getLongValue(String key) |
Obtains the
long value matching the specified key in the map of this ZSONObject. |
<T> T |
getObject(String key,
Class<T> clazz) |
Obtains the object matching the specified key in the map of this
ZSONObject and converts it into a class
object specified by clazz. |
Short |
getShort(String key) |
Obtains the
short value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Short object. |
short |
getShortValue(String key) |
Obtains the
short value matching the specified key in the map of this ZSONObject. |
String |
getString(String key) |
Obtains the
String object matching the specified key in the map of this ZSONObject. |
ZSONArray |
getZSONArray(String key) |
Obtains the array matching the specified key in the map of this
ZSONObject. |
ZSONObject |
getZSONObject(String key) |
Obtains the nested child
ZSONObject matching the specified key in the map of the parent
ZSONObject. |
boolean |
isEmpty() |
Checks whether this
ZSONObject contains no object. |
Set<String> |
keySet() |
Obtains the map that stores keys in this
ZSONObject. |
Object |
put(String key,
Object value) |
Puts a specified key-value pair to the map of this
ZSONObject. |
void |
putAll(Map<? extends String,?> m) |
Puts a map of key-value pairs into the map of this
ZSONObject. |
Object |
remove(Object key) |
|
int |
size() |
Obtains the size of this
ZSONObject. |
static <T> T |
stringToClass(String text,
Class<T> clazz) |
Converts a given JSON string to an object of the
Class type. |
static ZSONObject |
stringToZSON(String text) |
Converts a given JSON string to an object of the
ZSONObject type. |
String |
toString() |
Converts this
ZSONObject object into a JSON string. |
ZSONArray |
toZSONArray(String[] names) |
Obtains a list of values matching the keys contained in the
names array from this ZSONObject
instance. |
static String |
toZSONString(Object object) |
Converts a given object to a JSON string.
|
Collection<Object> |
values() |
Obtains the
Collection that stores values in this ZSONObject. |
public ZSONObject()
ZSONObject instance.public static final <T> T stringToClass(String text, Class<T> clazz)
Class type.text - Indicates the JSON-compliant string to be converted.clazz - Indicates the Class type of the object to return.Class type.ZSONException - Throws this exception when any error occurs.public static final ZSONObject stringToZSON(String text)
ZSONObject type.text - Indicates the JSON string to be converted.ZSONObject type if the string is successfully converted;
Otherwise, return null.ZSONException - Throws this exception when any error occurs.public static final String toZSONString(Object object)
object - Indicates the object to be converted.ZSONException - Throws this exception when any error occurs.public static final ZSONObject classToZSON(Object object)
ZSONObject.object - Indicates the class object to convert.ZSONObject.ZSONException - Throws this exception when any error occurs.public int size()
ZSONObject.ZSONObject.public boolean isEmpty()
ZSONObject contains no object.true if this ZSONObject contains no object; returns false otherwise.public boolean containsKey(Object key)
ZSONObject contains an object matching the specified key.key - Indicates the key stored in the map of this ZSONObject.true if the map of this ZSONObject contains an object matching the specified key;
returns false otherwise.public boolean containsValue(Object value)
ZSONObject contains a value object.value - Indicates the value stored in the map of this ZSONObject.true if the map of this ZSONObject contains a value object; returns false
otherwise.public Object get(Object key)
ZSONObject.key - Indicates the key stored in the map of this ZSONObject.public ZSONObject getZSONObject(String key)
ZSONObject matching the specified key in the map of the parent
ZSONObject.key - Indicates the key stored in the map of the parent ZSONObject.ZSONObject, or null if the object is not found.public ZSONArray getZSONArray(String key)
ZSONObject.key - Indicates the key stored in the map of the parent ZSONObject.null if the array is not found.public <T> T getObject(String key, Class<T> clazz)
ZSONObject and converts it into a class
object specified by clazz.key - Indicates the key stored in the map of this ZSONObject.clazz - Indicates the class type of the object to return. This object is converted from the value stored in
the map of this ZSONObject.public Boolean getBoolean(String key)
boolean value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Boolean object.key - Indicates the key stored in the map of this ZSONObject.Boolean object.public boolean getBooleanValue(String key)
boolean value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.boolean value.public byte[] getBytes(String key)
byte array matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.byte array.public Byte getByte(String key)
byte value matching the specified key in the map of this ZSONObject and automatically
converts the value into a Byte object.key - Indicates the key stored in the map of this ZSONObject.Byte object.public byte getByteValue(String key)
byte value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.byte value.public Short getShort(String key)
short value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Short object.key - Indicates the key stored in the map of this ZSONObject.Short object.public short getShortValue(String key)
short value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.short value.public Integer getInteger(String key)
int value matching the specified key in the map of this ZSONObject and automatically
converts the value into an Integer object.key - Indicates the key stored in the map of this ZSONObject.Integer object.public int getIntValue(String key)
int value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.int value.public Long getLong(String key)
long value matching the specified key in the map of this ZSONObject and automatically
converts the value into a Long object.key - Indicates the key stored in the map of this ZSONObject.Long object.public long getLongValue(String key)
long value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.long value.public Float getFloat(String key)
float value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Float object.key - Indicates the key stored in the map of this ZSONObject.Float object.public float getFloatValue(String key)
float value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.float value.public Double getDouble(String key)
double value matching the specified key in the map of this ZSONObject and
automatically converts the value into a Double object.key - Indicates the key stored in the map of this ZSONObject.Double object.public double getDoubleValue(String key)
double value matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.double value.public BigDecimal getBigDecimal(String key)
BigDecimal object matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.BigDecimal object.public BigInteger getBigInteger(String key)
BigInteger object matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.BigInteger object.public String getString(String key)
String object matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.String object.public Date getDate(String key)
Date object matching the specified key in the map of this ZSONObject.key - Indicates the key stored in the map of this ZSONObject.Date object.public Object put(String key, Object value)
ZSONObject.key - Indicates the key to be stored in the map of this ZSONObject.value - Indicates the value to be stored in the map of this ZSONObject.value associated with key.public void putAll(Map<? extends String,?> m)
ZSONObject.m - Indicates the map to put. Its keys are String objects or the objects from which it extends.public void clear()
ZSONObject.public Set<String> keySet()
ZSONObject.ZSONObject.public Collection<Object> values()
Collection that stores values in this ZSONObject.Collection that stores values in this ZSONObject.public Set<Map.Entry<String,Object>> entrySet()
entrySet in the map of this ZSONObject.entrySet in the map of this ZSONObject.public ZSONArray toZSONArray(String[] names)
names array from this ZSONObject
instance.
The list is a ZSONArray instance whose elements are ordered in the same sequence as names.
names - Indicates the keys whose values are to be obtained.ZSONArray instance.NullPointerException - Throws this exception if names is null.