本文整理了Java中org.apache.sling.commons.json.JSONArray.optString()
方法的一些代码示例,展示了JSONArray.optString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.optString()
方法的具体详情如下:
包路径:org.apache.sling.commons.json.JSONArray
类名称:JSONArray
方法名:optString
[英]Get the optional string value associated with an index. It returns an empty string if there is no value at that index. If the value is not a string and is not null, then it is coverted to a string.
[中]获取与索引关联的可选字符串值。如果该索引处没有值,则返回空字符串。如果值不是字符串且不为null,则将其转换为字符串。
代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json
/**
* Get the optional string value associated with an index. It returns an
* empty string if there is no value at that index. If the value
* is not a string and is not null, then it is coverted to a string.
*
* @param index The index must be between 0 and length() - 1.
* @return A String value.
*/
public String optString(int index) {
return optString(index, "");
}
代码示例来源:origin: io.wcm/io.wcm.handler.richtext
/**
* Support legacy data structures where link metadata is stored as JSON fragment in single HTML5 data attribute.
* @param resourceProps ValueMap to write link metadata to
* @param element Link element
*/
private boolean getAnchorLegacyMetadataFromSingleData(ValueMap resourceProps, Element element) {
boolean foundAny = false;
JSONObject metadata = null;
Attribute dataAttribute = element.getAttribute("data");
if (dataAttribute != null) {
String metadataString = dataAttribute.getValue();
if (StringUtils.isNotEmpty(metadataString)) {
try {
metadata = new JSONObject(metadataString);
}
catch (JSONException ex) {
log.debug("Invalid link metadata: " + metadataString, ex);
}
}
}
if (metadata != null) {
JSONArray names = metadata.names();
for (int i = 0; i < names.length(); i++) {
String name = names.optString(i);
resourceProps.put(name, metadata.opt(name));
foundAny = true;
}
}
return foundAny;
}
代码示例来源:origin: io.wcm/io.wcm.handler.richtext
if (metadataPropertyNames != null) {
for (int i = 0; i < metadataPropertyNames.length(); i++) {
String metadataPropertyName = metadataPropertyNames.optString(i);
values.add(valueArray.optString(j));
代码示例来源:origin: io.wcm/io.wcm.handler.richtext
String[] values = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
values[i] = jsonArray.optString(i);
内容来源于网络,如有侵权,请联系作者删除!