Package ch.epfl.cs107.play.data.json
Class JSONArray
java.lang.Object
ch.epfl.cs107.play.data.json.JSONValue
ch.epfl.cs107.play.data.json.JSONArray
Used to represent json arrays
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends the given value to the arraybooleanChecks if the array contains the given valueget(int index) Returns the value at the given indexprotected static JSONArrayParses the given json into a JSONArrayvoidremove(int index) Removes the value at the given indexvoidSets the value at the given indexintsize()Returns the size of the arrayprotected StringSerializes the implementing class to a JSON-formatted string.
-
Constructor Details
-
JSONArray
public JSONArray()
-
-
Method Details
-
get
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
Sets the value at the given index- Parameters:
index- (int): The index of the value to setvalue- (JSONValue): The new value
-
append
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
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
Description copied from class:JSONValueSerializes the implementing class to a JSON-formatted string.- Specified by:
toJSONStringin classJSONValue- Returns:
- A JSON-formatted string representation of the object.
-
parse
Parses the given json into a JSONArray- Parameters:
json- (String): The json to parse- Returns:
- (JSONArray): The parsed array
-