Package playn.core

Interface Json.Array

Enclosing interface:
Json

public static interface Json.Array
Represents a parsed JSON array as a simple int->value map.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(int index, Object value)
    Inserts a JSON boolean, null, number, object, or array value at the given index.
    add(Object value)
    Appends a JSON boolean, null, number, object, or array value.
    getArray(int index)
    Gets the array value at the given index, or null if there is no value at this index.
    getArray(int index, Class<T> jsonType)
    Gets an array at the given index that assumes its values are of the given json type, or null if there is no value at this index.
    getArray(int index, Json.Array dflt)
    Gets the array value at the given index, or the default if there is no value at this index.
    boolean
    getBoolean(int index)
    Gets the boolean value at the given index, or false if there is no value at this index.
    boolean
    getBoolean(int index, boolean dflt)
    Gets the boolean value at the given index, or the default if there is no value at this index.
    double
    getDouble(int index)
    Gets the double value at the given index, or 0 if there is no value at this index.
    double
    getDouble(int index, double dflt)
    Gets the double value at the given index, or the default if there is no value at this index.
    int
    getInt(int index)
    Gets the integer value at the given index, or 0 if there is no value at this index.
    int
    getInt(int index, int dflt)
    Gets the integer value at the given index, or the default if there is no value at this index.
    long
    getLong(int index)
    Gets the long value at the given index, or 0 if there is no value at this index.
    long
    getLong(int index, long dflt)
    Gets the long value at the given index, or the default if there is no value at this index.
    float
    getNumber(int index)
    Gets the float value at the given index, or 0 if there is no value at this index.
    float
    getNumber(int index, float dflt)
    Gets the float value at the given index, or the default if there is no value at this index.
    getObject(int index)
    Gets the object value at the given index, or null if there is no value at this index.
    getObject(int index, Json.Object dflt)
    Gets the object value at the given index, or the default if there is no value at this index.
    getString(int index)
    Gets the string value at the given index, or null if there is no value at this index.
    getString(int index, String dflt)
    Gets the string value at the given index, or the default if there is no value at this index.
    boolean
    isArray(int index)
    Returns true if the value at the given index is an array.
    boolean
    isBoolean(int index)
    Returns true if the value at the given index is a boolean.
    boolean
    isNull(int index)
    Returns true if the value at the given index is null, or does not exist.
    boolean
    isNumber(int index)
    Returns true if the value at the given index is a number.
    boolean
    isObject(int index)
    Returns true if the value at the given index is an object.
    boolean
    isString(int index)
    Returns true if the value at the given index is a string.
    int
    Gets the length of this array.
    remove(int index)
    Removes a JSON value from the given index.
    set(int index, Object value)
    Sets a JSON boolean, null, number, object, or array value at the given index.
    <T extends playn.core.json.JsonSink<T>>
    playn.core.json.JsonSink<T>
    write(playn.core.json.JsonSink<T> sink)
    Writes this object to a JsonSink.
  • Method Details

    • length

      int length()
      Gets the length of this array.
    • getBoolean

      boolean getBoolean(int index)
      Gets the boolean value at the given index, or false if there is no value at this index.
    • getBoolean

      boolean getBoolean(int index, boolean dflt)
      Gets the boolean value at the given index, or the default if there is no value at this index.
    • getNumber

      float getNumber(int index)
      Gets the float value at the given index, or 0 if there is no value at this index.
    • getNumber

      float getNumber(int index, float dflt)
      Gets the float value at the given index, or the default if there is no value at this index.
    • getDouble

      double getDouble(int index)
      Gets the double value at the given index, or 0 if there is no value at this index.
    • getDouble

      double getDouble(int index, double dflt)
      Gets the double value at the given index, or the default if there is no value at this index.
    • getInt

      int getInt(int index)
      Gets the integer value at the given index, or 0 if there is no value at this index.
    • getInt

      int getInt(int index, int dflt)
      Gets the integer value at the given index, or the default if there is no value at this index.
    • getLong

      long getLong(int index)
      Gets the long value at the given index, or 0 if there is no value at this index. NOTE: this is not accurate on the HTML backend as all numbers are represented as doubles, which cannot represent all possible long values. This is included for projects that use only the other backends and need long values.
    • getLong

      long getLong(int index, long dflt)
      Gets the long value at the given index, or the default if there is no value at this index. NOTE: this is not accurate on the HTML backend as all numbers are represented as doubles, which cannot represent all possible long values. This is included for projects that use only the other backends and need long values.
    • getString

      String getString(int index)
      Gets the string value at the given index, or null if there is no value at this index.
    • getString

      String getString(int index, String dflt)
      Gets the string value at the given index, or the default if there is no value at this index.
    • getObject

      Json.Object getObject(int index)
      Gets the object value at the given index, or null if there is no value at this index.
    • getObject

      Json.Object getObject(int index, Json.Object dflt)
      Gets the object value at the given index, or the default if there is no value at this index.
    • getArray

      Json.Array getArray(int index)
      Gets the array value at the given index, or null if there is no value at this index.
    • getArray

      Json.Array getArray(int index, Json.Array dflt)
      Gets the array value at the given index, or the default if there is no value at this index.
    • getArray

      <T> Json.TypedArray<T> getArray(int index, Class<T> jsonType)
      Gets an array at the given index that assumes its values are of the given json type, or null if there is no value at this index.
      Parameters:
      jsonType - one of Json.Object, Json.Array, Boolean, Integer, Float, Double, or String
      Throws:
      IllegalArgumentException - if jsonType is of an invalid type.
    • isArray

      boolean isArray(int index)
      Returns true if the value at the given index is an array.
    • isBoolean

      boolean isBoolean(int index)
      Returns true if the value at the given index is a boolean.
    • isNull

      boolean isNull(int index)
      Returns true if the value at the given index is null, or does not exist.
    • isNumber

      boolean isNumber(int index)
      Returns true if the value at the given index is a number.
    • isString

      boolean isString(int index)
      Returns true if the value at the given index is a string.
    • isObject

      boolean isObject(int index)
      Returns true if the value at the given index is an object.
    • add

      Json.Array add(Object value)
      Appends a JSON boolean, null, number, object, or array value.
      Returns:
      a reference to this, allowing the calls to be chained together.
    • add

      Json.Array add(int index, Object value)
      Inserts a JSON boolean, null, number, object, or array value at the given index. If the index is past the end of the array, the array is null-padded to the given index.
      Returns:
      a reference to this, allowing the calls to be chained together.
    • remove

      Json.Array remove(int index)
      Removes a JSON value from the given index. If the index is out of bounds, this is a no-op.
      Returns:
      a reference to this, allowing the calls to be chained together.
    • set

      Json.Array set(int index, Object value)
      Sets a JSON boolean, null, number, object, or array value at the given index. If the index is past the end of the array, the array is null-padded to the given index.
      Returns:
      a reference to this, allowing the calls to be chained together.
    • write

      <T extends playn.core.json.JsonSink<T>> playn.core.json.JsonSink<T> write(playn.core.json.JsonSink<T> sink)
      Writes this object to a JsonSink.