Package net.minidev.json
Class JSONObject
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,java.lang.Object>
-
- net.minidev.json.JSONObject
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,java.lang.Object>,JSONAware,JSONAwareEx,JSONStreamAware,JSONStreamAwareEx
public class JSONObject extends java.util.HashMap<java.lang.String,java.lang.Object> implements JSONAware, JSONAwareEx, JSONStreamAwareEx
A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description JSONObject()JSONObject(java.util.Map<java.lang.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 java.lang.Stringescape(java.lang.String s)Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).java.lang.NumbergetAsNumber(java.lang.String key)A Simple Helper cast an Object to an Numberjava.lang.StringgetAsString(java.lang.String key)A Simple Helper object to Stringvoidmerge(java.lang.Object o2)protected static JSONArraymerge(JSONArray o1, java.lang.Object o2)private static JSONArraymerge(JSONArray o1, JSONArray o2)protected static JSONObjectmerge(JSONObject o1, java.lang.Object o2)private static JSONObjectmerge(JSONObject o1, JSONObject o2)java.lang.StringtoJSONString()static java.lang.StringtoJSONString(java.util.Map<java.lang.String,? extends java.lang.Object> map)static java.lang.StringtoJSONString(java.util.Map<java.lang.String,? extends java.lang.Object> map, JSONStyle compression)Convert a map to JSON text.java.lang.StringtoJSONString(JSONStyle compression)java.lang.StringtoString()java.lang.StringtoString(JSONStyle compression)static voidwriteJSON(java.util.Map<java.lang.String,? extends java.lang.Object> map, java.lang.Appendable out)static voidwriteJSON(java.util.Map<java.lang.String,? extends java.lang.Object> map, java.lang.Appendable out, JSONStyle compression)Encode a map into JSON text and write it to out.static voidwriteJSONKV(java.lang.String key, java.lang.Object value, java.lang.Appendable out, JSONStyle compression)Write a Key : value entry to a streamvoidwriteJSONString(java.lang.Appendable out)serialize Object as json to an streamvoidwriteJSONString(java.lang.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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
escape
public static java.lang.String escape(java.lang.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 java.lang.String toJSONString(java.util.Map<java.lang.String,? extends java.lang.Object> map)
-
toJSONString
public static java.lang.String toJSONString(java.util.Map<java.lang.String,? extends java.lang.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)
-
writeJSONKV
public static void writeJSONKV(java.lang.String key, java.lang.Object value, java.lang.Appendable out, JSONStyle compression) throws java.io.IOExceptionWrite a Key : value entry to a stream- Throws:
java.io.IOException
-
getAsString
public java.lang.String getAsString(java.lang.String key)
A Simple Helper object to String- Returns:
- a value.toString() or null
-
getAsNumber
public java.lang.Number getAsNumber(java.lang.String key)
A Simple Helper cast an Object to an Number- Returns:
- a Number or null
-
writeJSON
public static void writeJSON(java.util.Map<java.lang.String,? extends java.lang.Object> map, java.lang.Appendable out) throws java.io.IOException- Throws:
java.io.IOException
-
writeJSON
public static void writeJSON(java.util.Map<java.lang.String,? extends java.lang.Object> map, java.lang.Appendable out, JSONStyle compression) throws java.io.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:
java.io.IOException- See Also:
JSONValue.writeJSONString(Object, Appendable)
-
writeJSONString
public void writeJSONString(java.lang.Appendable out) throws java.io.IOExceptionserialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAware- Throws:
java.io.IOException
-
writeJSONString
public void writeJSONString(java.lang.Appendable out, JSONStyle compression) throws java.io.IOExceptionserialize Object as json to an stream- Specified by:
writeJSONStringin interfaceJSONStreamAwareEx- Throws:
java.io.IOException
-
merge
public void merge(java.lang.Object o2)
-
merge
protected static JSONObject merge(JSONObject o1, java.lang.Object o2)
-
merge
private static JSONObject merge(JSONObject o1, JSONObject o2)
-
toJSONString
public java.lang.String toJSONString()
- Specified by:
toJSONStringin interfaceJSONAware- Returns:
- JSON text
-
toJSONString
public java.lang.String toJSONString(JSONStyle compression)
- Specified by:
toJSONStringin interfaceJSONAwareEx- Returns:
- JSON text
-
toString
public java.lang.String toString(JSONStyle compression)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
-