本文整理了Java中org.apache.sling.commons.json.JSONObject.optJSONObject()
方法的一些代码示例,展示了JSONObject.optJSONObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optJSONObject()
方法的具体详情如下:
包路径:org.apache.sling.commons.json.JSONObject
类名称:JSONObject
方法名:optJSONObject
[英]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.
[中]获取与键关联的可选JSONObject。如果没有这样的键,或者其值不是JSONObject,则返回null。
代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle
/**
* Visit each JSON Object in the JSON Array.
*
* @param jsonObject The JSON Array
*/
protected final void traverseJSONObject(final JSONObject jsonObject) {
if (jsonObject == null) {
return;
}
final Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
final String key = keys.next();
if (jsonObject.optJSONObject(key) != null) {
this.accept(jsonObject.optJSONObject(key));
} else if (jsonObject.optJSONArray(key) != null) {
this.accept(jsonObject.optJSONArray(key));
}
}
}
代码示例来源: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: com.adobe.acs/acs-aem-commons-bundle
final JSONObject incomingJsonForm = jsonData.optJSONObject(KEY_FORM);
if (incomingJsonForm != null) {
data = TypeUtil.toMap(incomingJsonForm, String.class);
final JSONObject incomingJsonErrors = jsonData.optJSONObject(KEY_ERRORS);
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Append a JSON Object
*
* @param o
* @return
* @throws JSONException
*/
public JSONWriter writeObject(JSONObject o) throws JSONException {
Iterator<String> keys = o.keys();
this.object();
while (keys.hasNext()) {
String key = keys.next();
this.key(key);
JSONObject objVal = o.optJSONObject(key);
if (objVal != null) {
this.writeObject(objVal);
continue;
}
JSONArray arrVal = o.optJSONArray(key);
if (arrVal != null) {
this.writeArray(arrVal);
continue;
}
Object obj = o.opt(key);
this.value(obj);
}
this.endObject();
return this;
}
内容来源于网络,如有侵权,请联系作者删除!