public final class JsonModelHelper extends Object
Constructor and Description |
---|
JsonModelHelper(JSONObject jsonObject) |
public JsonModelHelper(JSONObject jsonObject)
jsonObject
- the JSON object to retrieve values from.public Object get(String name) throws JSONException
name
- the key name.JSONException
- if no such mapping exists.JSONObject.get(String)
public boolean getBoolean(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into a boolean.JSONObject.getBoolean(String)
public double getDouble(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into a double.JSONObject.getDouble(String)
public int getInt(String key) throws JSONException
key
- the key name.JSONException
- if the value cannot be coerced into an int.JSONObject.getInt(String)
public JSONArray getJSONArray(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into a JSONArray.JSONObject.getJSONArray(String)
public JSONObject getJSONObject(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into a JSONObject.JSONObject.getJSONObject(String)
public long getLong(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into an long.JSONObject.getLong(String)
public MonetaryValue getMonetaryValue(String name) throws JSONException
name
- the key name.JSONException
- if the value isn't a number or is missing.public String getString(String name) throws JSONException
name
- the key name.JSONException
- if the value cannot be coerced into an String.JSONObject.getString(String)
public boolean isNull(String name)
JSONObject.NULL
.name
- the name of the object to check for.public boolean has(String name)
name
- the name of the object to check for.JSONObject
has a value for the name passed.public Object opt(String name)
name
- the key name.null
if it is missing.JSONObject.opt(String)
public boolean optBoolean(String name)
name
- the key name.false
if it cannot be coerced into a booleanJSONObject.optBoolean(String)
public boolean optBoolean(String name, boolean fallback)
name
- the key name.fallback
- the value to be returned if the mapping is missing or null.fallback
if it's null.JSONObject.optBoolean(String, boolean)
public double optDouble(String name)
name
- the key name.0.0d
if it cannot be coerced into a double.JSONObject.optDouble(String)
public double optDouble(String name, double fallback)
name
- the key name.fallback
- the value to be returned if the mapping is missing or null.fallback
if it's null.JSONObject.optDouble(String, double)
public int optInt(String name)
name
- the key name.0
if it cannot be coerced into an int.JSONObject.optInt(String)
public int optInt(String name, int fallback)
name
- the key name.fallback
- the value to be returned if the mapping is missing or null.fallback
if it's null.JSONObject.optLong(String, long)
public JSONArray optJSONArray(String name)
name
- the key name.null
otherwise.JSONObject.optJSONArray(String)
public JSONObject optJSONObject(String name)
name
- the key name.null
otherwise.JSONObject.optJSONObject(String)
public long optLong(String name)
name
- the key name.0L
if it's null.public long optLong(String name, long fallback)
name
- the key name.fallback
- the fallback value if the mapping is missing or null.fallback
if it's null.JSONObject.optLong(String, long)
public Long optLongNullable(String name)
name
- the key name.null
if it's null.public MonetaryValue optMonetaryValue(String name) throws JSONException
name
- the key name.null
if it's null or missing.JSONException
- if the value isn't a number.public String optString(String name)
name
- the key name.null
if it's null or missing.JsonUtils.optString(JSONObject, String)
public String optString(String name, String fallback)
name
- the key name.fallback
- the fallback value if the mapping is missing or null.fallback
if it's null.JSONObject.optString(String, String)
public Set<String> optStringSet(String name) throws JSONException
name
- the key name.null
if it's null or missing.JSONException
- if the array contents aren't stringsJsonUtils.optStringSet(JSONObject, String)