Package net.minidev.json
Class JSONObject
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,Object> JSONAware,JSONAwareEx,JSONStreamAware,JSONStreamAwareEx
A JSON object. Key value pairs are unordered. JSONObject supports
java.util.Map interface.
- Author:
- FangYidong <[email protected]>, Uriel Chemouni <[email protected]>
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionJSONObject(int initialCapacity) JSONObject(Map<String, ?> map) Allows creation of a JSONObject from a Map. -
Method Summary
Modifier and TypeMethodDescriptionappendField(String fieldName, Object fieldValue) Puts value to object and returns this.static StringEscape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).getAsNumber(String key) A Simple Helper cast an Object to an NumbergetAsString(String key) A Simple Helper object to Stringvoidprotected static JSONArrayprotected static JSONObjectmerge(JSONObject o1, Object o2) static StringtoJSONString(Map<String, ? extends Object> map) static StringtoJSONString(Map<String, ? extends Object> map, JSONStyle compression) Convert a map to JSON text.toJSONString(JSONStyle compression) toString()static voidwriteJSON(Map<String, ? extends Object> map, Appendable out) static voidEncode a map into JSON text and write it to out.static voidwriteJSONKV(String key, Object value, Appendable out, JSONStyle compression) Write a Key : value entry to a streamvoidserialize Object as json to an streamvoidwriteJSONString(Appendable out, JSONStyle compression) serialize Object as json to an streamMethods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode
-
Constructor Details
-
JSONObject
public JSONObject() -
JSONObject
public JSONObject(int initialCapacity) -
JSONObject
Allows creation of a JSONObject from a Map. After that, both the generated JSONObject and the Map can be modified independently.
-
-
Method Details
-
escape
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F). It's the same as JSONValue.escape() only for compatibility here.- See Also:
-
toJSONString
-
toJSONString
Convert a map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.- Parameters:
map-- Returns:
- JSON text, or "null" if map is null.
- See Also:
-
writeJSONKV
public static void writeJSONKV(String key, Object value, Appendable out, JSONStyle compression) throws IOException Write a Key : value entry to a stream- Throws:
IOException
-
appendField
Puts value to object and returns this. Handy alternative to put(String key, Object value) method.- Parameters:
fieldName- key with which the specified value is to be associatedfieldValue- value to be associated with the specified key- Returns:
- this
-
getAsString
A Simple Helper object to String- Returns:
- a value.toString() or null
-
getAsNumber
A Simple Helper cast an Object to an Number- Returns:
- a Number or null
-
writeJSON
- Throws:
IOException
-
writeJSON
public static void writeJSON(Map<String, ? extends Object> map, Appendable out, JSONStyle compression) throws IOExceptionEncode a map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware or JSONStreamAware specific behaviours will be ignored at this top level.- Throws:
IOException- See Also:
-
writeJSONString
serialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAware- Throws:
IOException
-
writeJSONString
serialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAwareEx- Throws:
IOException
-
merge
-
merge
-
merge
-
toJSONString
- Specified by:
toJSONStringin interfaceJSONAware- Returns:
- JSON text
-
toJSONString
- Specified by:
toJSONStringin interfaceJSONAwareEx- Returns:
- JSON text
-
toString
-
toString
- Overrides:
toStringin classAbstractMap<String,Object>
-