Class JSONObject

    • 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>
    • 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 Number
      java.lang.String getAsString​(java.lang.String key)
      A Simple Helper object to String
      void 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 stream
      void writeJSONString​(java.lang.Appendable out)
      serialize Object as json to an stream
      void 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
      • 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<java.lang.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

      • 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 interface JSONStreamAware
        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 interface JSONStreamAwareEx
        Throws:
        java.io.IOException
      • merge

        public void merge​(java.lang.Object o2)
      • toJSONString

        public java.lang.String toJSONString()
        Specified by:
        toJSONString in interface JSONAware
        Returns:
        JSON text
      • toString

        public java.lang.String toString​(JSONStyle compression)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​java.lang.Object>