Class JSONObject

java.lang.Object
ch.epfl.cs107.play.data.json.JSONValue
ch.epfl.cs107.play.data.json.JSONObject

public class JSONObject extends JSONValue
Used to represent json objects
  • Constructor Details

    • JSONObject

      public JSONObject()
  • Method Details

    • add

      public JSONObject add(String key, JSONValue value)
      Adds a value to this object
      Parameters:
      key - (String): The key of the value to add
      value - (JSONValue): The value to add
      Returns:
      (JSONObject): This object
    • get

      public Map<String,JSONValue> get()
      Returns all the values in this object
      Returns:
      The value of this object
    • get

      public JSONValue get(String key)
      Returns the value with the given key
      Parameters:
      key - (String): The key of the value to return
      Returns:
      (JSONValue): The value with the given key
    • containsKey

      public boolean containsKey(String key)
      Returns whether this object contains the given key
      Parameters:
      key - (String): The key to check
      Returns:
      (boolean): Whether this object contains the given key
    • remove

      public JSONObject remove(String key)
      Removes the value with the given key
      Parameters:
      key - (String): The key of the value to remove
      Returns:
      (JSONObject): This object
    • keySet

      public Set<String> keySet()
      Returns the set of keys in this object
      Returns:
      The set of keys in this object
    • toJSONString

      protected String toJSONString()
      Description copied from class: JSONValue
      Serializes the implementing class to a JSON-formatted string.
      Specified by:
      toJSONString in class JSONValue
      Returns:
      A JSON-formatted string representation of the object.
    • parse

      protected static JSONObject parse(List<String> lines)
      Parses a list of lines into a JSONObject
      Parameters:
      lines - The lines to parse
      Returns:
      (JSONObject): The parsed JSONObject