Class JSONArray

java.lang.Object
dev.iahmadgad.json.JSONArray

public class JSONArray extends Object
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 Details

    • indentation

      protected int indentation
      Indentation and space around colon in the String.
    • spaceAroundColon

      protected int spaceAroundColon
      Indentation and space around colon in the String.
  • Constructor Details

    • JSONArray

      public JSONArray()
      The main Constructor which initialises a new JSONArray.
    • JSONArray

      public JSONArray(String text)
      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

      public JSONArray(List<T> list)
      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

      public Object[] toArray()
      Converts JSONArray to a Java array.
      Returns:
      An array of objects (only valid)
    • toStringArray

      public String[] 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

      public List<Object> toList()
      Converts JSONArray to a Java list.
      Returns:
      A list of Objects (only valid)
    • toStringList

      public List<String> toStringList()
      Converts JSONArray to a Java String list.
      Returns:
      A list of Strings
    • toBooleanList

      public List<Boolean> toBooleanList()
      Converts JSONArray to a Java boolean String list.
      Returns:
      A list of booleans
    • toIntegerList

      public List<Integer> toIntegerList()
      Converts JSONArray to a Java Integer list.
      Returns:
      A list of Integers
    • toDoubleList

      public List<Double> toDoubleList()
      Converts JSONArray to a Java Double list.
      Returns:
      A list of Doubles
    • toString

      public String toString()
      Returns a string representation of the JSONArray.
      Overrides:
      toString in class Object
    • setIndentation

      public void setIndentation(int i)
      Sets indentation with some int value.
      Parameters:
      i -
    • setIndentation

      public void setIndentation(JSONEnum e)
      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

      public void setSpaceAroundColon(JSONEnum e)
      Sets space around colon with some Enum value.
      Parameters:
      e -
    • setStringDefault

      public void setStringDefault()
      Sets all String settings to their defaults.
    • getNode

      public ArrayList<Object> getNode()
      Returns the main ArrayList that stores JSONArray values.
      Returns:
      node
    • setNode

      protected void setNode(ArrayList<Object> array)
    • 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

      public void add(Object value)
      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

      public void set(int index, Object value)
      Replaces the value in the specified position with the the specified value.
      Parameters:
      index -
      value -
    • get

      public Object get(int index)
      Gets Object in this index.
      Parameters:
      index -
      Returns:
      Object value
    • getString

      public String getString(int index)
      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

      public JSONObject getJSONObject(int index)
      Gets JSONObject in this index.
      Parameters:
      index -
      Returns:
      JSONObject value
    • getJSONArray

      public JSONArray getJSONArray(int index)
      Gets JSONArray in this index.
      Parameters:
      index -
      Returns:
      JSONArray value
    • get

      public Object get(JSONPointer pointer)
      Gets Object in this pointer.
      Parameters:
      pointer -
      Returns:
      Object value
    • getString

      public String getString(JSONPointer pointer)
      Gets String in this pointer.
      Parameters:
      pointer -
      Returns:
      String value
    • getBoolean

      public boolean getBoolean(JSONPointer pointer)
      Gets boolean in this pointer.
      Parameters:
      pointer -
      Returns:
      boolean value
    • getInt

      public int getInt(JSONPointer pointer)
      Gets int in this pointer.
      Parameters:
      pointer -
      Returns:
      int value
    • getDouble

      public double getDouble(JSONPointer pointer)
      Gets double in this pointer.
      Parameters:
      pointer -
      Returns:
      double value
    • getJSONObject

      public JSONObject getJSONObject(JSONPointer pointer)
      Gets JSONObject in this pointer.
      Parameters:
      pointer -
      Returns:
      JSONObject value
    • getJSONArray

      public JSONArray getJSONArray(JSONPointer pointer)
      Gets JSONArray in this pointer.
      Parameters:
      pointer -
      Returns:
      JSONArray value