Package dev.iahmadgad.json
Class JSONArray
java.lang.Object
dev.iahmadgad.json.JSONArray
JSONArray Class.
JSONArray is an array contains an ordered sequence of values, values can only be integers, doubles, booleans, or nested JSONObjects and JSONArrays, but it can't be chars or any other type.
- Since:
- 0.3
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
Indentation and space around colon in the String.protected int
Indentation and space around colon in the String. -
Constructor Summary
ConstructorDescriptionThe main Constructor which initialises a new JSONArray.The Constructor which creates a new JSONArray from a text.The Constructor which creates a new JSONArray from a Java list (with valid values only as mentioned above).JSONArray
(T[] array) The Constructor which creates a new JSONArray from a Java array (with valid values only as mentioned above). -
Method Summary
Modifier and TypeMethodDescriptionvoid
Appends the specified value to the end of the JSONArray.<T> void
addAll
(T[] array) Appends the specified array to the end of the JSONArray.get
(int index) Gets Object in this index.get
(JSONPointer pointer) Gets Object in this pointer.boolean
getBoolean
(int index) Gets boolean in this index.boolean
getBoolean
(JSONPointer pointer) Gets boolean in this pointer.double
getDouble
(int index) Gets double in this index.double
getDouble
(JSONPointer pointer) Gets double in this pointer.int
getInt
(int index) Gets int in this index.int
getInt
(JSONPointer pointer) Gets int in this pointer.getJSONArray
(int index) Gets JSONArray in this index.getJSONArray
(JSONPointer pointer) Gets JSONArray in this pointer.getJSONObject
(int index) Gets JSONObject in this index.getJSONObject
(JSONPointer pointer) Gets JSONObject in this pointer.getNode()
Returns the main ArrayList that stores JSONArray values.getString
(int index) Gets String in this index.getString
(JSONPointer pointer) Gets String in this pointer.void
remove
(int index) Removes the value stored in this index.void
Replaces the value in the specified position with the the specified value.void
setIndentation
(int i) Sets indentation with some int value.void
Sets indentation with some Enum value.protected void
void
setSpaceAroundColon
(int i) Sets space around colon with some int value.void
Sets space around colon with some Enum value.void
Sets all String settings to their defaults.int
size()
Returns the size of the main ArrayList that stores JSONArray values.Object[]
toArray()
Converts JSONArray to a Java array.<T> T[]
toArray
(T[] a) Converts the JSONArray to a Java array.boolean[]
Converts JSONArray to a Java boolean array.Converts JSONArray to a Java boolean String list.double[]
Converts JSONArray to a Java double array.Converts JSONArray to a Java Double list.int[]
Converts JSONArray to a Java int array.Converts JSONArray to a Java Integer list.toList()
Converts JSONArray to a Java list.toString()
Returns a string representation of the JSONArray.String[]
Converts JSONArray to a Java String array.Converts JSONArray to a Java String list.
-
Field Details
-
indentation
protected int indentationIndentation and space around colon in the String. -
spaceAroundColon
protected int spaceAroundColonIndentation and space around colon in the String.
-
-
Constructor Details
-
JSONArray
public JSONArray()The main Constructor which initialises a new JSONArray. -
JSONArray
The Constructor which creates a new JSONArray from a text.- Parameters:
text
- Source JSON string (text)
-
JSONArray
public JSONArray(T[] array) The Constructor which creates a new JSONArray from a Java array (with valid values only as mentioned above).- Parameters:
array
- Source Java Array
-
JSONArray
The Constructor which creates a new JSONArray from a Java list (with valid values only as mentioned above).- Parameters:
list
- Source Java List
-
-
Method Details
-
toArray
Converts JSONArray to a Java array.- Returns:
- An array of objects (only valid)
-
toStringArray
Converts JSONArray to a Java String array.- Returns:
- An array of Strings
-
toBooleanArray
public boolean[] toBooleanArray()Converts JSONArray to a Java boolean array.- Returns:
- An array of booleans
-
toIntArray
public int[] toIntArray()Converts JSONArray to a Java int array.- Returns:
- An array of ints
-
toDoubleArray
public double[] toDoubleArray()Converts JSONArray to a Java double array.- Returns:
- An array of doubles
-
toList
Converts JSONArray to a Java list.- Returns:
- A list of Objects (only valid)
-
toStringList
Converts JSONArray to a Java String list.- Returns:
- A list of Strings
-
toBooleanList
Converts JSONArray to a Java boolean String list.- Returns:
- A list of booleans
-
toIntegerList
Converts JSONArray to a Java Integer list.- Returns:
- A list of Integers
-
toDoubleList
Converts JSONArray to a Java Double list.- Returns:
- A list of Doubles
-
toString
Returns a string representation of the JSONArray. -
setIndentation
public void setIndentation(int i) Sets indentation with some int value.- Parameters:
i
-
-
setIndentation
Sets indentation with some Enum value.- Parameters:
e
-
-
setSpaceAroundColon
public void setSpaceAroundColon(int i) Sets space around colon with some int value.- Parameters:
i
-
-
setSpaceAroundColon
Sets space around colon with some Enum value.- Parameters:
e
-
-
setStringDefault
public void setStringDefault()Sets all String settings to their defaults. -
getNode
Returns the main ArrayList that stores JSONArray values.- Returns:
node
-
setNode
-
size
public int size()Returns the size of the main ArrayList that stores JSONArray values.- Returns:
- the size of the main ArrayList
-
toArray
public <T> T[] toArray(T[] a) Converts the JSONArray to a Java array.- Parameters:
a
- Java array- Returns:
- An array of the same type
-
add
Appends the specified value to the end of the JSONArray.- Parameters:
value
-
-
addAll
public <T> void addAll(T[] array) Appends the specified array to the end of the JSONArray.- Type Parameters:
T
-- Parameters:
array
- array of type T
-
remove
public void remove(int index) Removes the value stored in this index.- Parameters:
index
-
-
set
Replaces the value in the specified position with the the specified value.- Parameters:
index
-value
-
-
get
Gets Object in this index.- Parameters:
index
-- Returns:
- Object value
-
getString
Gets String in this index.- Parameters:
index
-- Returns:
- String value
-
getBoolean
public boolean getBoolean(int index) Gets boolean in this index.- Parameters:
index
-- Returns:
- boolean value
-
getInt
public int getInt(int index) Gets int in this index.- Parameters:
index
-- Returns:
- int value
-
getDouble
public double getDouble(int index) Gets double in this index.- Parameters:
index
-- Returns:
- double value
-
getJSONObject
Gets JSONObject in this index.- Parameters:
index
-- Returns:
- JSONObject value
-
getJSONArray
Gets JSONArray in this index.- Parameters:
index
-- Returns:
- JSONArray value
-
get
Gets Object in this pointer.- Parameters:
pointer
-- Returns:
- Object value
-
getString
Gets String in this pointer.- Parameters:
pointer
-- Returns:
- String value
-
getBoolean
Gets boolean in this pointer.- Parameters:
pointer
-- Returns:
- boolean value
-
getInt
Gets int in this pointer.- Parameters:
pointer
-- Returns:
- int value
-
getDouble
Gets double in this pointer.- Parameters:
pointer
-- Returns:
- double value
-
getJSONObject
Gets JSONObject in this pointer.- Parameters:
pointer
-- Returns:
- JSONObject value
-
getJSONArray
Gets JSONArray in this pointer.- Parameters:
pointer
-- Returns:
- JSONArray value
-