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 long
serialVersionUID
-
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.String
escape(java.lang.String s)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).java.lang.Number
getAsNumber(java.lang.String key)
A Simple Helper cast an Object to an Numberjava.lang.String
getAsString(java.lang.String key)
A Simple Helper object to Stringvoid
merge(java.lang.Object o2)
protected static JSONArray
merge(JSONArray o1, java.lang.Object o2)
private static JSONArray
merge(JSONArray o1, JSONArray o2)
protected static JSONObject
merge(JSONObject o1, java.lang.Object o2)
private static JSONObject
merge(JSONObject o1, JSONObject o2)
java.lang.String
toJSONString()
static java.lang.String
toJSONString(java.util.Map<java.lang.String,? extends java.lang.Object> map)
static java.lang.String
toJSONString(java.util.Map<java.lang.String,? extends java.lang.Object> map, JSONStyle compression)
Convert a map to JSON text.java.lang.String
toJSONString(JSONStyle compression)
java.lang.String
toString()
java.lang.String
toString(JSONStyle compression)
static void
writeJSON(java.util.Map<java.lang.String,? extends java.lang.Object> map, java.lang.Appendable out)
static void
writeJSON(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 void
writeJSONKV(java.lang.String key, java.lang.Object value, java.lang.Appendable out, JSONStyle compression)
Write a Key : value entry to a streamvoid
writeJSONString(java.lang.Appendable out)
serialize Object as json to an streamvoid
writeJSONString(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.IOException
Write 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.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:
java.io.IOException
- See Also:
JSONValue.writeJSONString(Object, Appendable)
-
writeJSONString
public void writeJSONString(java.lang.Appendable out) throws java.io.IOException
serialize Object as json to an stream- Specified by:
writeJSONString
in interfaceJSONStreamAware
- Throws:
java.io.IOException
-
writeJSONString
public void writeJSONString(java.lang.Appendable out, JSONStyle compression) throws java.io.IOException
serialize Object as json to an stream- Specified by:
writeJSONString
in 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:
toJSONString
in interfaceJSONAware
- Returns:
- JSON text
-
toJSONString
public java.lang.String toJSONString(JSONStyle compression)
- Specified by:
toJSONString
in interfaceJSONAwareEx
- Returns:
- JSON text
-
toString
public java.lang.String toString(JSONStyle compression)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
-