Package playn.core

Interface Json.Object

Enclosing interface:
Json

public static interface Json.Object
Represents a parsed JSON object as a simple string->value map.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if this object contains a value at the specified key, false if not.
    Gets the array value at the given key, or null if there is no value at this key.
    getArray(String key, Class<T> jsonType)
    Gets an array at the given key that assumes its values are of the given json type, or null if there is no value at this key.
    getArray(String key, Class<T> jsonType, Json.TypedArray<T> dflt)
    Gets an array at the given key that assumes its values are of the given json type, or the default if there is no value at this key.
    Gets the array value at the given key, or the default if there is no value at this key.
    boolean
    Gets the boolean value at the given key, or false if there is no value at this key.
    boolean
    getBoolean(String key, boolean dflt)
    Gets the boolean value at the given key, or the default if there is no value at this key.
    double
    Gets the double value at the given key, or 0 if there is no value at this key.
    double
    getDouble(String key, double dflt)
    Gets the double value at the given key, or the default if there is no value at this key.
    int
    Gets the integer value at the given key, or 0 if there is no value at this key.
    int
    getInt(String key, int dflt)
    Gets the integer value at the given key, or the default if there is no value at this key.
    long
    Gets the long value at the given key, or 0 if there is no value at this key.
    long
    getLong(String key, long dflt)
    Gets the long value at the given key, or the default if there is no value at this key.
    float
    Gets the float value at the given key, or 0 if there is no value at this key.
    float
    getNumber(String key, float dflt)
    Gets the float value at the given key, or the default if there is no value at this key.
    Gets the object value at the given key, or null if there is no value at this key.
    Gets the object value at the given key, or the default if there is no value at this key.
    Gets the string value at the given key, or null if there is no value at this key.
    getString(String key, String dflt)
    Gets the string value at the given key, or the default if there is no value at this key.
    boolean
    Returns true if the value at the given key is an array.
    boolean
    Returns true if the value at the given key is a boolean.
    boolean
    Returns true if the value at the given key is null or does not exist.
    boolean
    Returns true if the value at the given key is a number.
    boolean
    Returns true if the value at the given key is an object.
    boolean
    Returns true if the value at the given key is a string.
    Gets a snapshot of the current set of keys for this JSON object.
    put(String key, Object value)
    Inserts a JSON null, object, array or string value at the given key.
    Removes a JSON value at the given key.
    <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

    • getBoolean

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

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

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

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

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

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

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

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

      long getLong(String key)
      Gets the long value at the given key, or 0 if there is no value at this key. 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(String key, long dflt)
      Gets the long value at the given key, or the default if there is no value at this key. 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(String key)
      Gets the string value at the given key, or null if there is no value at this key.
    • getString

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

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

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

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

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

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

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

      boolean containsKey(String key)
      Returns true if this object contains a value at the specified key, false if not.
    • keys

      Gets a snapshot of the current set of keys for this JSON object. Modifications to the object will not be reflected in this set of keys.
    • isArray

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

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

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

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

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

      boolean isObject(String key)
      Returns true if the value at the given key is an object.
    • put

      Json.Object put(String key, Object value)
      Inserts a JSON null, object, array or string value at the given key.
      Returns:
      a reference to this, allowing the calls to be chained together.
    • remove

      Json.Object remove(String key)
      Removes a JSON value at the given key.
      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.