Class JSONArray

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess, JSONAware, JSONAwareEx, JSONStreamAware, JSONStreamAwareEx

public class JSONArray extends ArrayList<Object> implements JSONAwareEx, JSONStreamAwareEx
A JSON array. JSONObject supports java.util.List interface.
Author:
FangYidong <[email protected]>, Uriel Chemouni <[email protected]>
See Also:
  • Constructor Details

    • JSONArray

      public JSONArray()
    • JSONArray

      public JSONArray(int initialCapacity)
  • Method Details

    • toJSONString

      public static String toJSONString(List<? extends Object> list)
    • toJSONString

      public static String toJSONString(List<? extends Object> list, JSONStyle compression)
      Convert a list to JSON text. The result is a JSON array. If this list is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.
      Parameters:
      list -
      compression - Indicate compression level
      Returns:
      JSON text, or "null" if list is null.
      See Also:
    • writeJSONString

      public static void writeJSONString(Iterable<? extends Object> list, Appendable out, JSONStyle compression) throws IOException
      Encode a list into JSON text and write it to out. If this list is also a JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific behaviours will be ignored at this top level.
      Parameters:
      list -
      out -
      Throws:
      IOException
      See Also:
    • writeJSONString

      public static void writeJSONString(List<? extends Object> list, Appendable out) throws IOException
      Encode a list into JSON text and write it to out. If this list is also a JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific behaviours will be ignored at this top level.
      Parameters:
      list -
      out -
      Throws:
      IOException
    • appendElement

      public JSONArray appendElement(Object element)
      Appends the specified element and returns this. same effect that add(E e) method.
      Parameters:
      element - element to be appended to this array.
      Returns:
      this
    • merge

      public void merge(Object o2)
      Merges the specified object into this array. can trigger an add(E e) or addAll(E e) method.
      Parameters:
      o2 -
    • toJSONString

      public String toJSONString()
      Explicitly Serialize Object as JSon String
      Specified by:
      toJSONString in interface JSONAware
      Returns:
      JSON text
    • toJSONString

      public String toJSONString(JSONStyle compression)
      Description copied from interface: JSONAwareEx
      Converts this object to JSON string representation with specified compression style.
      Specified by:
      toJSONString in interface JSONAwareEx
      Parameters:
      compression - the JSON style for formatting
      Returns:
      JSON text
    • toString

      public String toString()
      Override native toString()
      Overrides:
      toString in class AbstractCollection<Object>
    • toString

      public String toString(JSONStyle compression)
      JSONAwareEx interface
      Parameters:
      compression - compression param
    • writeJSONString

      public void writeJSONString(Appendable out) throws IOException
      JSONStreamAwareEx interface
      Specified by:
      writeJSONString in interface JSONStreamAware
      Parameters:
      out - output stream
      Throws:
      IOException - if I/O error occurs
    • writeJSONString

      public void writeJSONString(Appendable out, JSONStyle compression) throws IOException
      JSONStreamAwareEx interface
      Specified by:
      writeJSONString in interface JSONStreamAwareEx
      Parameters:
      out - output stream
      compression - compression param
      Throws:
      IOException - if I/O error occurs