mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-08 03:24:27 +08:00
Add optJSONArray method to JSONObject with a default value
This commit is contained in:
@@ -1512,8 +1512,22 @@ public class JSONObject {
|
||||
* @return A JSONArray which is the value.
|
||||
*/
|
||||
public JSONArray optJSONArray(String key) {
|
||||
Object o = this.opt(key);
|
||||
return o instanceof JSONArray ? (JSONArray) o : null;
|
||||
return this.optJSONArray(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an optional JSONArray associated with a key, or the default if there
|
||||
* is no such key, or if its value is not a JSONArray.
|
||||
*
|
||||
* @param key
|
||||
* A key string.
|
||||
* @param defaultValue
|
||||
* The default.
|
||||
* @return A JSONArray which is the value.
|
||||
*/
|
||||
public JSONArray optJSONArray(String key, JSONArray defaultValue) {
|
||||
Object object = this.opt(key);
|
||||
return object instanceof JSONArray ? (JSONArray) object : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user