net.minidev.json
Class JSONObject

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,Object>
          extended by 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,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
JSONObject()
           
JSONObject(Map<String,?> map)
          Allows creation of a JSONObject from a Map.
 
Method Summary
<T> T
cast()
          Allow simply casting to Map
static String escape(String s)
          Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
protected static JSONArray merge(JSONArray o1, Object o2)
           
protected static JSONObject merge(JSONObject o1, Object o2)
           
 void merge(Object o2)
           
 String toJSONString()
           
 String toJSONString(JSONStyle compression)
           
static String toJSONString(Map<String,Object> map)
           
static String toJSONString(Map<String,Object> map, JSONStyle compression)
          Convert a map to JSON text.
 String toString()
           
 String toString(JSONStyle compression)
           
static String toString(String key, Object value)
           
static String toString(String key, Object value, JSONStyle compression)
           
 void writeJSONString(Appendable out)
          serialize Object as json to an stream
 void writeJSONString(Appendable out, JSONStyle compression)
          serialize Object as json to an stream
static void writeJSONString(Map<String,Object> map, Appendable out)
           
static void writeJSONString(Map<String,Object> map, Appendable out, JSONStyle compression)
          Encode a map into JSON text and write it to out.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

JSONObject

public JSONObject()

JSONObject

public JSONObject(Map<String,?> map)
Allows creation of a JSONObject from a Map. After that, both the generated JSONObject and the Map can be modified independently.

Method Detail

cast

public <T> T cast()
Allow simply casting to Map


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,Object> map)

toJSONString

public static String toJSONString(Map<String,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)

toString

public static String toString(String key,
                              Object value)

toString

public static String toString(String key,
                              Object value,
                              JSONStyle compression)

writeJSONString

public static void writeJSONString(Map<String,Object> map,
                                   Appendable out)
                            throws IOException
Throws:
IOException

writeJSONString

public static void writeJSONString(Map<String,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:
writeJSONString in interface JSONStreamAware
Throws:
IOException

writeJSONString

public void writeJSONString(Appendable out,
                            JSONStyle compression)
                     throws IOException
serialize Object as json to an stream

Specified by:
writeJSONString in interface JSONStreamAwareEx
Throws:
IOException

merge

public void merge(Object o2)

merge

protected static JSONObject merge(JSONObject o1,
                                  Object o2)

merge

protected static JSONArray merge(JSONArray o1,
                                 Object o2)

toJSONString

public String toJSONString()
Specified by:
toJSONString in interface JSONAware
Returns:
JSON text

toJSONString

public String toJSONString(JSONStyle compression)
Specified by:
toJSONString in interface JSONAwareEx
Returns:
JSON text

toString

public String toString(JSONStyle compression)

toString

public String toString()
Overrides:
toString in class AbstractMap<String,Object>


Copyright © 2011 Chemouni Uriel. All Rights Reserved.