本文整理了Java中org.json.JSONObject.opt()
方法的一些代码示例,展示了JSONObject.opt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.opt()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:opt
[英]Returns the value mapped by name, or null if no such mapping exists.
[中]返回按名称映射的值,如果不存在此类映射,则返回null。
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get an optional JSONObject associated with a key. It returns null if
* there is no such key, or if its value is not a JSONObject.
*
* @param key
* A key string.
* @return A JSONObject which is the value.
*/
public JSONObject optJSONObject(String key) {
Object object = this.opt(key);
return object instanceof JSONObject ? (JSONObject) object : null;
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get an optional JSONArray associated with a key. It returns null if there
* is no such key, or if its value is not a JSONArray.
*
* @param key
* A key string.
* @return A JSONArray which is the value.
*/
public JSONArray optJSONArray(String key) {
Object o = this.opt(key);
return o instanceof JSONArray ? (JSONArray) o : null;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONArray}. Returns null otherwise.
*/
public JSONArray optJSONArray(String name) {
Object object = opt(name);
return object instanceof JSONArray ? (JSONArray) object : null;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONObject}. Returns null otherwise.
*/
public JSONObject optJSONObject(String name) {
Object object = opt(name);
return object instanceof JSONObject ? (JSONObject) object : null;
}
代码示例来源:origin: apache/geode
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONArray}, or null otherwise.
*
* @param name The name of the field we want.
* @return The value of the specified field (assuming it is a JSNOArray
*/
public JSONArray optJSONArray(String name) {
Object object = opt(name);
return object instanceof JSONArray ? (JSONArray) object : null;
}
代码示例来源:origin: apache/geode
/**
* Returns the value mapped by {@code name} if it exists and is a {@code
* JSONObject}, or null otherwise.
*
* @param name The name of the value we want.
* @return The specified value.
*/
public JSONObject optJSONObject(String name) {
Object object = opt(name);
return object instanceof JSONObject ? (JSONObject) object : null;
}
代码示例来源:origin: alibaba/Tangram-Android
public Object optParam(String key) {
if (extras.has(key)) {
return extras.opt(key);
}
if (style != null && style.extras != null) {
return style.extras.opt(key);
}
return null;
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Determine if the value associated with the key is null or if there is no
* value.
*
* @param key
* A key string.
* @return true if there is no value associated with the key or if the value
* is the JSONObject.NULL object.
*/
public boolean isNull(String key) {
return JSONObject.NULL.equals(this.opt(key));
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get an optional string associated with a key. It returns the defaultValue
* if there is no such key.
*
* @param key
* A key string.
* @param defaultValue
* The default.
* @return A string which is the value.
*/
public String optString(String key, String defaultValue) {
Object object = this.opt(key);
return NULL.equals(object) ? defaultValue : object.toString();
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a long or
* can be coerced to a long. Returns {@code fallback} otherwise. Note that JSON represents
* numbers as doubles, so this is <a href="#lossy">lossy</a>; use strings to transfer
* numbers via JSON.
*/
public long optLong(String name, long fallback) {
Object object = opt(name);
Long result = JSON.toLong(object);
return result != null ? result : fallback;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a boolean or
* can be coerced to a boolean. Returns {@code fallback} otherwise.
*/
public boolean optBoolean(String name, boolean fallback) {
Object object = opt(name);
Boolean result = JSON.toBoolean(object);
return result != null ? result : fallback;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is an int or
* can be coerced to an int. Returns {@code fallback} otherwise.
*/
public int optInt(String name, int fallback) {
Object object = opt(name);
Integer result = JSON.toInteger(object);
return result != null ? result : fallback;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists and is a double or
* can be coerced to a double. Returns {@code fallback} otherwise.
*/
public double optDouble(String name, double fallback) {
Object object = opt(name);
Double result = JSON.toDouble(object);
return result != null ? result : fallback;
}
代码示例来源:origin: robovm/robovm
/**
* Returns the value mapped by {@code name} if it exists, coercing it if
* necessary. Returns {@code fallback} if no such mapping exists.
*/
public String optString(String name, String fallback) {
Object object = opt(name);
String result = JSON.toString(object);
return result != null ? result : fallback;
}
代码示例来源:origin: alibaba/Tangram-Android
private void parseBizParams(BaseCell cell, JSONObject json) {
if (json == null) {
return;
}
Iterator<String> iterator = json.keys();
while (iterator.hasNext()) {
String key = iterator.next();
cell.addBizParam(key, json.opt(key));
}
}
代码示例来源:origin: apache/geode
public GfJsonObject getJSONObject(String key) {
Object opt = jsonObject.opt(key);
if (opt instanceof GfJsonObject) {
return (GfJsonObject) opt;
}
if (opt == null) {
return null;
}
return new GfJsonObject(opt);
}
代码示例来源:origin: facebook/facebook-android-sdk
static boolean jsonObjectContainsValue(JSONObject jsonObject, Object value) {
@SuppressWarnings("unchecked")
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
Object thisValue = jsonObject.opt(keys.next());
if (thisValue != null && thisValue.equals(value)) {
return true;
}
}
return false;
}
代码示例来源:origin: facebook/facebook-android-sdk
static Collection<Object> jsonObjectValues(JSONObject jsonObject) {
ArrayList<Object> result = new ArrayList<Object>();
@SuppressWarnings("unchecked")
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
result.add(jsonObject.opt(keys.next()));
}
return result;
}
}
代码示例来源:origin: facebook/facebook-android-sdk
static Set<Map.Entry<String, Object>> jsonObjectEntrySet(JSONObject jsonObject) {
HashSet<Map.Entry<String, Object>> result = new HashSet<Map.Entry<String, Object>>();
@SuppressWarnings("unchecked")
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = jsonObject.opt(key);
result.add(new JSONObjectEntry(key, value));
}
return result;
}
代码示例来源:origin: json-path/JsonPath
@Override
public Object getMapValue(Object obj, String key) {
try {
JSONObject jsonObject = toJsonObject(obj);
Object o = jsonObject.opt(key);
if (o == null) {
return UNDEFINED;
} else {
return unwrap(o);
}
} catch (JSONException e) {
throw new JsonPathException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!