Class JSONArray

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

public class JSONArray extends JSONValue
Used to represent json arrays
  • Constructor Details

    • JSONArray

      public JSONArray()
  • Method Details

    • get

      public JSONValue get(int index)
      Returns the value at the given index
      Parameters:
      index - (int): The index of the value to return
      Returns:
      (JSONValue): The value at the given index
    • set

      public void set(int index, JSONValue value)
      Sets the value at the given index
      Parameters:
      index - (int): The index of the value to set
      value - (JSONValue): The new value
    • append

      public void append(JSONValue value)
      Appends the given value to the array
      Parameters:
      value - (JSONValue): The value to append
    • remove

      public void remove(int index)
      Removes the value at the given index
      Parameters:
      index - (int): The index of the value to remove
    • contains

      public boolean contains(JSONValue value)
      Checks if the array contains the given value
      Parameters:
      value - (JSONValue): The value to check
      Returns:
      (boolean): True if the array contains the value, false otherwise
    • size

      public int size()
      Returns the size of the array
      Returns:
      (int): The size of the array
    • 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 JSONArray parse(String json)
      Parses the given json into a JSONArray
      Parameters:
      json - (String): The json to parse
      Returns:
      (JSONArray): The parsed array