Class PJsonObject

All Implemented Interfaces:
PObject

public class PJsonObject extends PAbstractObject
Wrapper around the JSONObject class to have a better error management.
  • Constructor Details

    • PJsonObject

      public PJsonObject(org.json.JSONObject obj, String contextName)
      Constructor.
      Parameters:
      obj - the internal json element
      contextName - the field name of this element in the parent.
    • PJsonObject

      public PJsonObject(PElement parent, org.json.JSONObject obj, String contextName)
      Constructor.
      Parameters:
      parent - the parent element
      obj - the internal json element
      contextName - the field name of this element in the parent.
  • Method Details

    • opt

      public final Object opt(String key)
      Description copied from interface: PObject
      Get the value for the key.
      Parameters:
      key - the key identifying the value to obtain.
    • optString

      public final String optString(String key)
      Get a property as a string or null.
      Parameters:
      key - the property name
    • optInt

      public final Integer optInt(String key)
      Get a property as a int or null.
      Parameters:
      key - the property name
    • optLong

      public final Long optLong(String key)
      Description copied from interface: PObject
      Get a property as a long or MIN_VALUE.
      Parameters:
      key - the property name
    • optDouble

      public final Double optDouble(String key)
      Get a property as a double or null.
      Parameters:
      key - the property name
    • optFloat

      public final Float optFloat(String key)
      Get a property as a float or null.
      Parameters:
      key - the property name
    • optBool

      public final Boolean optBool(String key)
      Get a property as a boolean or null.
      Parameters:
      key - the property name
    • optObject

      public final PObject optObject(String key)
      Get a property as a object or null.
      Parameters:
      key - the property name
    • optArray

      public final PArray optArray(String key)
      Get a property as a array or null.
      Parameters:
      key - the property name
    • isArray

      public final boolean isArray(String key)
      Description copied from interface: PObject
      Is the property an array.
      Parameters:
      key - the property name
    • optJSONObject

      public final PJsonObject optJSONObject(String key)
      Get a property as a json object or null.
      Parameters:
      key - the property name
    • getJSONObject

      public final PJsonObject getJSONObject(String key)
      Get a property as a json object or throw exception.
      Parameters:
      key - the property name
    • getJSONArray

      public final PJsonArray getJSONArray(String key)
      Get a property as a json array or throw exception.
      Parameters:
      key - the property name
    • optJSONArray

      public final PJsonArray optJSONArray(String key)
      Get a property as a json array or null.
      Parameters:
      key - the property name
    • optJSONArray

      public final PJsonArray optJSONArray(String key, PJsonArray defaultValue)
      Get a property as a json array or default.
      Parameters:
      key - the property name
      defaultValue - default
    • keys

      public final Iterator<String> keys()
      Get an iterator of all keys in this objects.
      Returns:
      The keys iterator
    • size

      public final int size()
      Get the number of properties in this object.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getInternalObj

      public final org.json.JSONObject getInternalObj()
      Get the internal json object.
      Returns:
      The internal object
    • has

      public final boolean has(String key)
      Check if the object has a property with the key.
      Parameters:
      key - key to check for.
    • toString

      public final String toString()
      Overrides:
      toString in class Object