本文整理了Java中org.apache.sling.commons.json.JSONObject.get()
方法的一些代码示例,展示了JSONObject.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.get()
方法的具体详情如下:
包路径:org.apache.sling.commons.json.JSONObject
类名称:JSONObject
方法名:get
[英]Get the value object associated with a key.
[中]获取与键关联的值对象。
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the int value associated with a key. If the number value is too
* large for an int, it will be clipped.
*
* @param key A key string.
* @return The integer value.
* @throws JSONException if the key is not found or if the value cannot
* be converted to an integer.
*/
public int getInt(String key) throws JSONException {
Object o = get(key);
return o instanceof Number ?
((Number)o).intValue() : (int)getDouble(key);
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
@Override
public Object get(String key) throws JSONException {
if(key.equals(nameKey)) {
return name;
}
return jsonObject.get(key);
}
代码示例来源:origin: otros-systems/otroslogviewer
private static Map<String, String> toMap(JSONObject j, Map<String, String> map, String prefix) throws JSONException {
final Iterator<String> keys = j.keys();
while (keys.hasNext()) {
final String key = keys.next();
final Object o = j.get(key);
if (o instanceof JSONObject) {
JSONObject jso = (JSONObject) o;
toMap(jso, map, prefix + key + VALUES_SEPARATOR);
} else {
map.put(prefix + key, j.getString(key));
}
}
return map;
}
代码示例来源:origin: io.wcm/io.wcm.caconfig.editor
Object value = properties.get(propertyName);
if (value instanceof JSONArray) {
JSONArray values = (JSONArray)value;
代码示例来源:origin: io.wcm/io.wcm.caconfig.editor
private ConfigurationCollectionPersistData parseCollectionConfigData(JSONObject jsonData, ConfigurationMetadata configMetadata) throws JSONException {
List<ConfigurationPersistData> items = new ArrayList<>();
JSONArray itemsObject = jsonData.getJSONArray("items");
for (int i = 0; i < itemsObject.length(); i++) {
JSONObject item = itemsObject.getJSONObject(i);
items.add(parseConfigData(item, configMetadata));
}
Map<String, Object> properties = null;
JSONObject propertiesObject = jsonData.optJSONObject("properties");
if (propertiesObject != null) {
properties = new HashMap<>();
Iterator<String> propertyNames = propertiesObject.keys();
while (propertyNames.hasNext()) {
String propertyName = propertyNames.next();
properties.put(propertyName, propertiesObject.get(propertyName));
}
}
return new ConfigurationCollectionPersistData(items)
.properties(properties);
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the string associated with a key.
*
* @param key A key string.
* @return A string which is the value.
* @throws JSONException if the key is not found.
*/
public String getString(String key) throws JSONException {
return get(key).toString();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the long value associated with a key. If the number value is too
* long for a long, it will be clipped.
*
* @param key A key string.
* @return The long value.
* @throws JSONException if the key is not found or if the value cannot
* be converted to a long.
*/
public long getLong(String key) throws JSONException {
Object o = get(key);
return o instanceof Number ?
((Number)o).longValue() :
Long.valueOf((String)o).longValue();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the double value associated with a key.
* @param key A key string.
* @return The numeric value.
* @throws JSONException if the key is not found or
* if the value is not a Number object and cannot be converted to a number.
*/
public double getDouble(String key) throws JSONException {
Object o = get(key);
try {
return o instanceof Number ?
((Number)o).doubleValue() :
Double.valueOf((String)o).doubleValue();
} catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) +
"] is not a number.");
}
}
代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle
/**
* Converts a JSONObject to a simple Map. This will only work properly for
* JSONObjects of depth 1.
* <p/>
* Resulting map will be type'd <String, T> where T is the type of the second parameter (klass)
*
* @param json
* @param klass
* @return
*/
@SuppressWarnings("unchecked")
public static <T> Map<String, T> toMap(JSONObject json, Class<T> klass) throws JSONException {
final HashMap<String, T> map = new HashMap<String, T>();
final List<?> keys = IteratorUtils.toList(json.keys());
for (final Object key : keys) {
final String strKey = key.toString();
final Object obj = json.get(strKey);
if (klass.isInstance(obj)) {
// Only add objects of this type
map.put(strKey, (T) obj);
}
}
return map;
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the boolean value associated with a key.
*
* @param key A key string.
* @return The truth.
* @throws JSONException
* if the value is not a Boolean or the String "true" or "false".
*/
public boolean getBoolean(String key) throws JSONException {
Object o = get(key);
if (o.equals(Boolean.FALSE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("false"))) {
return false;
} else if (o.equals(Boolean.TRUE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a Boolean.");
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the JSONObject value associated with a key.
*
* @param key A key string.
* @return A JSONObject which is the value.
* @throws JSONException if the key is not found or
* if the value is not a JSONObject.
*/
public JSONObject getJSONObject(String key) throws JSONException {
Object o = get(key);
if (o instanceof JSONObject) {
return (JSONObject)o;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a JSONObject.");
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the JSONArray value associated with a key.
*
* @param key A key string.
* @return A JSONArray which is the value.
* @throws JSONException if the key is not found or
* if the value is not a JSONArray.
*/
public JSONArray getJSONArray(String key) throws JSONException {
Object o = get(key);
if (o instanceof JSONArray) {
return (JSONArray)o;
}
throw new JSONException("JSONObject[" + quote(key) +
"] is not a JSONArray.");
}
代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle
/**
* Load the base configuration and "underlay" it under the provided
* configuration so that the provided configuration overwrites the default
* configuration.
*
* @param config the configuration to underlay
* @param resource the resource to underlay
* @return the underlayed configuration
* @throws JSONException
* @throws ServletException
*/
protected final JSONObject underlay(JSONObject config, Resource resource)
throws JSONException, ServletException {
JSONObject baseStructure = toJSONObject(resource);
if (baseStructure != null) {
Iterator<String> keys = config.keys();
while (keys.hasNext()) {
String key = keys.next();
baseStructure.put(key, config.get(key));
}
return baseStructure;
} else {
return config;
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
writer.write(quote(k));
writer.write(':');
final Object v = jo.get(k);
if (v instanceof JSONObject) {
((JSONObject)v).write(writer);
代码示例来源:origin: io.wcm/io.wcm.testing.sling-mock
final String name = names.getString(i);
if (!IGNORED_NAMES.contains(name)) {
Object obj = jsonObject.get(name);
if (!(obj instanceof JSONObject)) {
this.setProperty(props, name, obj);
final String name = names.getString(i);
if (!IGNORED_NAMES.contains(name)) {
Object obj = jsonObject.get(name);
if (obj instanceof JSONObject) {
createResource(resource, name, (JSONObject)obj);
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
while (keys.hasNext()) {
k = keys.next();
v = jo.get(k);
if (v instanceof String) {
s = (String)v;
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
if (n == 1) {
o = keys.next();
final Object v = jo.get(o);
if(!skipChildObject(children, opt, o, v)) {
sb.append(quote(o));
while (keys.hasNext()) {
o = keys.next();
final Object v = jo.get(o);
if(skipChildObject(children, opt, o, v)) {
continue;
内容来源于网络,如有侵权,请联系作者删除!