Class JSONObject


public class JSONObject extends JSONComplex
Representation of a JSON object, a collection (unordered) of name/value pairs. An example: {"name":"Homer", "age":40, "children":["Bart", "Maggie", "Lisa"]}
  • Field Details

  • Constructor Details

    • JSONObject

      public JSONObject()
  • Method Details

    • size

      public int size()
      Specified by:
      size in class JSONComplex
    • getValue

      public HashMap<String,JSONValue> getValue()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • render

      protected String render(boolean aPretty, String aIndent)
      Description copied from class: JSONValue
      Convert the JSON value into a string representation (JSON representation).
      Specified by:
      render in class JSONValue
      Parameters:
      aPretty - Indicating if the print should be made pretty (human readers) or compact (transmission or storage).
      aIndent - Starting indent.
      Returns:
      A JSON representation.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • containsKey

      public boolean containsKey(String aKey)
    • get

      public JSONValue get(String aKey)
      Utility method, get the element with specified name without having to retreive the map first using getValue().
      Parameters:
      aKey - The key for which you want to retrieve the element.
      Returns:
      The element corresponding to the key or null if the object does not contain a key with this name.
    • strip

      public Object strip()
      Remove all JSON related information. In the case of a JSONObject, a HashMap is returned. The values of the HashMap are stripped as well.
      Specified by:
      strip in class JSONValue
      Returns:
      a HashMap, containing pure Java objects.