Class JSONObject

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map

    public class JSONObject
    extends java.util.HashMap
    A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.
    Author:
    FangYidong<fangyidong@yahoo.com.cn>
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONObject()  
      JSONObject​(java.util.Map 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).
      static java.lang.String toJSONString​(java.util.Map<?,​?> map)
      Convert a map to JSON text.
      java.lang.String toString()  
      static java.lang.String toString​(java.lang.String key, java.lang.Object value)  
      static void writeJSONString​(java.util.Map<?,​?> map, java.io.Writer out)
      Encode a map into JSON text and write it to out.
      • 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
      • 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​(java.util.Map map)
    • Method Detail

      • writeJSONString

        public static void writeJSONString​(java.util.Map<?,​?> map,
                                           java.io.Writer out)
                                    throws java.io.IOException
        Encode a map into JSON text and write it to out.
        Throws:
        java.io.IOException
        See Also:
        JSONValue.writeJSONString(Object, Writer)
      • toJSONString

        public static java.lang.String toJSONString​(java.util.Map<?,​?> map)
        Convert a map to JSON text. The result is a JSON object.
        Returns:
        JSON text, or "null" if map is null.
        See Also:
        JSONValue.toJSONString(Object)
      • toString

        public static java.lang.String toString​(java.lang.String key,
                                                java.lang.Object value)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap
      • 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)