本文整理了Java中org.codehaus.jettison.json.JSONObject.opt()
方法的一些代码示例,展示了JSONObject.opt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.opt()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:opt
[英]Get an optional value associated with a key.
[中]
代码示例来源:origin: json-path/JsonPath
@Override
public Object getMapValue(Object obj, String key)
{
Object value = ((org.codehaus.jettison.json.JSONObject)obj).opt(key);
if( value==null )
{
return com.jayway.jsonpath.spi.json.JsonProvider.UNDEFINED;
}
return jettisonUnwrap(value);
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* 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 o = opt(key);
return o instanceof JSONObject ? (JSONObject)o : null;
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* 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 = opt(key);
return o instanceof JSONArray ? (JSONArray)o : null;
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* 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(opt(key)) || JSONObject.EXPLICIT_NULL.equals(opt(key));
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* 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 o = opt(key);
return o != null ? o.toString() : defaultValue;
}
代码示例来源:origin: com.jayway.jsonpath/json-path
@Override
public Object getMapValue(Object obj, String key)
{
Object value = ((org.codehaus.jettison.json.JSONObject)obj).opt(key);
if( value==null )
{
return com.jayway.jsonpath.spi.json.JsonProvider.UNDEFINED;
}
return jettisonUnwrap(value);
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Construct a JSONObject from a subset of another JSONObject.
* An array of strings is used to identify the keys that should be copied.
* Missing keys are ignored.
* @param jo A JSONObject.
* @param sa An array of strings.
* @exception JSONException If a value is a non-finite number.
*/
public JSONObject(JSONObject jo, String[] sa) throws JSONException {
this();
for (int i = 0; i < sa.length; i += 1) {
putOpt(sa[i], jo.opt(sa[i]));
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get an optional long value associated with a key,
* or the default if there is no such key or if the value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public long optLong(String key, long defaultValue) {
Object o = opt(key);
if (o == null) {
return defaultValue;
} else {
try {
return doGetLong(key, o);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get an optional double associated with a key, or the
* defaultValue if there is no such key or if its value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public double optDouble(String key, double defaultValue) {
Object o = opt(key);
if (o == null) {
return defaultValue;
} else {
try {
return doGetDouble(key, o);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get an optional boolean associated with a key.
* It returns the defaultValue if there is no such key, or if it is not
* a Boolean or the String "true" or "false" (case insensitive).
*
* @param key A key string.
* @param defaultValue The default.
* @return The truth.
*/
public boolean optBoolean(String key, boolean defaultValue) {
Object o = opt(key);
if (o == null) {
return defaultValue;
} else {
try {
return doGetBoolean(key, o);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get an optional int value associated with a key,
* or the default if there is no such key or if the value is not a number.
* If the value is a string, an attempt will be made to evaluate it as
* a number.
*
* @param key A key string.
* @param defaultValue The default.
* @return An object which is the value.
*/
public int optInt(String key, int defaultValue) {
Object o = opt(key);
if (o == null) {
return defaultValue;
} else {
try {
return doGetInt(key, o);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get the value object associated with a key.
*
* @param key A key string.
* @return The object associated with the key.
* @throws JSONException if the key is not found.
*/
public Object get(String key) throws JSONException {
Object o = opt(key);
if (o == null) {
throw new JSONException("JSONObject[" + quote(key) +
"] not found.");
}
return o;
}
代码示例来源:origin: org.codehaus.jettison/jettison
Object o = object.opt(k);
k = k.substring(1);
if (k.equals("xmlns")) {
代码示例来源:origin: org.codehaus.jettison/jettison
Object o = object.opt( k );
代码示例来源:origin: org.codehaus.jettison/jettison
public void writeCharacters(String text) throws XMLStreamException {
text = text.trim();
if (text.length() == 0) {
return;
}
try {
Object o = getCurrentNode().opt("$");
if (o instanceof JSONArray) {
((JSONArray) o).put(text);
} else if (o instanceof String) {
JSONArray arr = new JSONArray();
arr.put(o);
arr.put(text);
getCurrentNode().put("$", arr);
} else {
getCurrentNode().put("$", text);
}
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Produce a JSONArray containing the values of the members of this
* JSONObject.
* @param names A JSONArray containing a list of key strings. This
* determines the sequence of the values in the result.
* @return A JSONArray of values.
* @throws JSONException If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(JSONArray names) throws JSONException {
if (names == null || names.length() == 0) {
return null;
}
JSONArray ja = new JSONArray();
for (int i = 0; i < names.length(); i += 1) {
ja.put(this.opt(names.getString(i)));
}
return ja;
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Append values to the array under a key. If the key does not exist in the
* JSONObject, then the key is put in the JSONObject with its value being a
* JSONArray containing the value parameter. If the key was already
* associated with a JSONArray, then the value parameter is appended to it.
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
* @throws JSONException If the key is null or if the current value
* associated with the key is not a JSONArray.
*/
public JSONObject append(String key, Object value)
throws JSONException {
testValidity(value);
Object o = opt(key);
if (o == null) {
put(key, new JSONArray().put(value));
} else if (!(o instanceof JSONArray)){
throw new JSONException("JSONObject[" + key +
"] is not a JSONArray.");
} else {
((JSONArray)o).put(value);
}
return this;
}
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Accumulate values under a key. It is similar to the put method except
* that if there is already an object stored under the key then a
* JSONArray is stored under the key to hold all of the accumulated values.
* If there is already a JSONArray, then the new value is appended to it.
* In contrast, the put method replaces the previous value.
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
* @throws JSONException If the value is an invalid number
* or if the key is null.
*/
public JSONObject accumulate(String key, Object value)
throws JSONException {
testValidity(value);
Object o = opt(key);
if (o == null) {
put(key, value);
} else if (o instanceof JSONArray) {
((JSONArray)o).put(value);
} else {
put(key, new JSONArray().put(o).put(value));
}
return this;
}
代码示例来源:origin: org.codehaus.jettison/jettison
value = convention.convertToJSONPrimitive((String)value);
Object old = object.opt(property.getKey());
try {
if(old != null) {
代码示例来源:origin: org.codehaus.jettison/jettison
Object existing = getCurrentNode().opt(currentKey);
if (existing instanceof JSONObject) {
JSONArray array = new JSONArray();
内容来源于网络,如有侵权,请联系作者删除!