public final class JsonObject extends Object implements Map<String,Object>, Serializable
| Constructor and Description |
|---|
JsonObject()
Constructs an empty insertion-ordered LinkedHashMap instance
with the default initial capacity (16) and load factor (0.75).
|
JsonObject(boolean ordered)
Constructs an empty Map instance with the default initial
capacity (16) and load factor (0.75).
|
JsonObject(int initialCapacity)
Constructs an empty insertion-ordered LinkedHashMap instance
with the specified initial capacity, and a default load factor (0.75).
|
JsonObject(int initialCapacity,
boolean ordered)
Constructs an empty Map with the default initial capacity (16)
and load factor (0.75).
|
JsonObject(Map<String,Object> src)
Constructs an Map instance with the same mappings as the
specified map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
Object |
clone() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,Object>> |
entrySet() |
boolean |
equals(Object obj) |
Object |
get(Object key) |
BigDecimal |
getAsBigDecimal(String key)
convenience method to get this element as a
BigDecimal. |
BigInteger |
getAsBigInteger(String key)
convenience method to get this element as a
BigInteger. |
boolean |
getAsBoolean(String key)
convenience method to get this element as a boolean value.
|
Byte |
getAsByte(String key)
convenience method to get this element as a primitive byte.
|
char |
getAsCharacter(String key)
convenience method to get this element as a primitive char.
|
Double |
getAsDouble(String key)
convenience method to get this element as a primitive double.
|
Float |
getAsFloat(String key)
convenience method to get this element as a Float.
|
Integer |
getAsInt(String key)
convenience method to get this element as a primitive integer.
|
JsonArray |
getAsJsonArray(String key)
Convenience method to get the specified key as a JsonArray.
|
JsonObject |
getAsJsonObject(String key)
Convenience method to get the specified key as a JsonObject.
|
<T> List<T> |
getAsList(String key)
Convenience method to get the specified key as a List.
|
Long |
getAsLong(String key)
convenience method to get this element as a primitive Long.
|
Number |
getAsNumber(String key)
convenience method to get this element as a Number.
|
Short |
getAsShort(String key)
convenience method to get this element as a primitive Short.
|
String |
getAsString(String key)
convenience method to get this element as a String.
|
int |
hashCode() |
boolean |
isEmpty() |
Set<String> |
keySet() |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,?> src) |
Object |
remove(Object key) |
int |
size() |
String |
toJson()
将对象序列化为JSON字符串
|
void |
toJson(Appendable writer)
将对象序列化为JSON字符串
|
String |
toString() |
Collection<Object> |
values() |
finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic JsonObject()
public JsonObject(Map<String,Object> src)
src - the map whose mappings are to be placed in this mapNullPointerException - if the specified map is nullpublic JsonObject(boolean ordered)
ordered - true: create LinkedHashMap; false: create
HashMappublic JsonObject(int initialCapacity)
initialCapacity - the initial capacityIllegalArgumentException - if the initial capacity is negativepublic JsonObject(int initialCapacity,
boolean ordered)
initialCapacity - the initial capacityordered - true: create LinkedHashMap; false: create
HashMapIllegalArgumentException - if the initial capacity is negativepublic boolean containsKey(Object key)
containsKey in interface Map<String,Object>public boolean containsValue(Object value)
containsValue in interface Map<String,Object>public boolean equals(Object obj)
public int hashCode()
public String toJson()
public void toJson(Appendable writer)
writer - 将JSON字符串写入到 Appendable 中public <T> List<T> getAsList(String key)
key - name of the element key.public JsonArray getAsJsonArray(String key)
key - name of the element key.public JsonObject getAsJsonObject(String key)
key - name of the element key.public boolean getAsBoolean(String key)
key - name of the element key.public Number getAsNumber(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid
Number.public String getAsString(String key)
key - name of the element key.public Double getAsDouble(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid
double.public BigDecimal getAsBigDecimal(String key)
BigDecimal.key - name of the element key.BigDecimal.NumberFormatException - if the value contained is not a valid
BigDecimal.public BigInteger getAsBigInteger(String key)
BigInteger.key - name of the element key.BigInteger.NumberFormatException - if the value contained is not a valid
BigInteger.public Float getAsFloat(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid
Float.public Long getAsLong(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid Long.public Short getAsShort(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid Short
value.public Integer getAsInt(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid
integer.public Byte getAsByte(String key)
key - name of the element key.NumberFormatException - if the value contained is not a valid byte.public char getAsCharacter(String key)
key - name of the element key.IndexOutOfBoundsException - if the index argument is
negative or not less than the length of this string.Copyright © 2018–2020. All rights reserved.