Package net.minidev.json
Class JSONObject
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Object>
-
- net.minidev.json.JSONObject
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,Object>,JSONAware,JSONAwareEx,JSONStreamAware,JSONStreamAwareEx
public class JSONObject extends HashMap<String,Object> implements JSONAware, JSONAwareEx, JSONStreamAwareEx
A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.- Author:
- FangYidong
, Uriel Chemouni - See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description JSONObject()JSONObject(Map<String,?> map)Allows creation of a JSONObject from a Map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Stringescape(String s)Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).voidmerge(Object o2)protected static JSONArraymerge(JSONArray o1, Object o2)protected static JSONObjectmerge(JSONObject o1, Object o2)StringtoJSONString()static StringtoJSONString(Map<String,? extends Object> map)static StringtoJSONString(Map<String,? extends Object> map, JSONStyle compression)Convert a map to JSON text.StringtoJSONString(JSONStyle compression)StringtoString()StringtoString(JSONStyle compression)static voidwriteJSON(Map<String,? extends Object> map, Appendable out, JSONStyle compression)Encode a map into JSON text and write it to out.static voidwriteJSON(Map<String,Object> map, Appendable out)voidwriteJSONString(Appendable out)serialize Object as json to an streamvoidwriteJSONString(Appendable out, JSONStyle compression)serialize Object as json to an stream-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
-
-
-
Method Detail
-
escape
public static String escape(String s)
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:
JSONValue.escape(String)
-
toJSONString
public static String toJSONString(Map<String,? extends Object> map, JSONStyle compression)
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:
JSONValue.toJSONString(Object)
-
writeJSON
public static void writeJSON(Map<String,Object> map, Appendable out) throws IOException
- Throws:
IOException
-
writeJSON
public static void writeJSON(Map<String,? extends Object> map, Appendable out, JSONStyle compression) throws IOException
Encode 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:
JSONValue.writeJSONString(Object, Appendable)
-
writeJSONString
public void writeJSONString(Appendable out) throws IOException
serialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAware- Throws:
IOException
-
writeJSONString
public void writeJSONString(Appendable out, JSONStyle compression) throws IOException
serialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAwareEx- Throws:
IOException
-
merge
public void merge(Object o2)
-
merge
protected static JSONObject merge(JSONObject o1, Object o2)
-
toJSONString
public String toJSONString()
- Specified by:
toJSONStringin interfaceJSONAware- Returns:
- JSON text
-
toJSONString
public String toJSONString(JSONStyle compression)
- Specified by:
toJSONStringin interfaceJSONAwareEx- Returns:
- JSON text
-
toString
public String toString()
- Overrides:
toStringin classAbstractMap<String,Object>
-
-