org.apache.sling.commons.json.JSONObject.keys()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中org.apache.sling.commons.json.JSONObject.keys()方法的一些代码示例,展示了JSONObject.keys()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.keys()方法的具体详情如下:
包路径:org.apache.sling.commons.json.JSONObject
类名称:JSONObject
方法名:keys

JSONObject.keys介绍

[英]Get an enumeration of the keys of the JSONObject.
[中]获取JSONObject键的枚举。

代码示例

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

NamedJSONObject(String name, JSONObject jsonObject, Options opt) {
  this.name = name;
  this.jsonObject = jsonObject;
  this.nameKey = opt.childNameKey;
  keysWithName = new ArrayList<String>();
  keysWithName.add(nameKey);
  final Iterator<String> it = jsonObject.keys();
  while(it.hasNext()) {
    keysWithName.add(it.next());
  }
}

代码示例来源: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: org.apache.sling/org.apache.sling.commons.json

/** Render the supplied JSONObject to a String, in
 *  the simplest possible way.
 */
public String toString(JSONObject jo) {
  try {
    final Iterator<String> keys = jo.keys();
    final StringBuffer sb = new StringBuffer("{");
    while (keys.hasNext()) {
      if (sb.length() > 1) {
        sb.append(',');
      }
      String o = keys.next();
      sb.append(quote(o));
      sb.append(':');
      sb.append(valueToString(jo.opt(o)));
    }
    sb.append('}');
    return sb.toString();
  } catch (Exception e) {
    return null;
  }
}

代码示例来源: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

/**
 * Produce a JSONArray containing the names of the elements of this
 * JSONObject.
 * @return A JSONArray containing the key strings, or null if the JSONObject
 * is empty.
 */
public JSONArray names() {
  JSONArray ja = new JSONArray();
  Iterator<String>  keys = keys();
  while (keys.hasNext()) {
    ja.put(keys.next());
  }
  return ja.length() == 0 ? null : ja;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

/**
   * Convert a JSONObject into a cookie list. A cookie list is a sequence
   * of name/value pairs. The names are separated from the values by '='.
   * The pairs are separated by ';'. The characters '%', '+', '=', and ';'
   * in the names and values are replaced by "%hh".
   * @param o A JSONObject
   * @return A cookie list string
   * @throws JSONException
   */
  public static String toString(JSONObject o) throws JSONException {
    boolean      b = false;
    Iterator<String>     keys = o.keys();
    String       s;
    StringBuffer sb = new StringBuffer();
    while (keys.hasNext()) {
      s = keys.next();
      if (!o.isNull(s)) {
        if (b) {
          sb.append(';');
        }
        sb.append(Cookie.escape(s));
        sb.append("=");
        sb.append(Cookie.escape(o.getString(s)));
        b = true;
      }
    }
    return sb.toString();
  }
}

代码示例来源: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: com.adobe.acs/acs-aem-commons-bundle

@Override
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource)
    throws JSONException {
  if (info.has(KEY_WORKFLOWS)) {
    final JSONObject workflows = info.getJSONObject(KEY_WORKFLOWS);
    final String resourcePath = resource.getPath();
    final ResourceResolver resourceResolver = resource.getResourceResolver();
    for (final Iterator<String> types = workflows.keys(); types.hasNext();) {
      final String type = types.next();
      final JSONObject typeObject = workflows.getJSONObject(type);
      filter(typeObject, resourcePath, resourceResolver);
    }
  } else {
    log.warn("No workflows found in existing page info. Check order of cq:infoProviders.");
  }
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@Override
@SuppressWarnings( "deprecation" )
public void updatePageInfo(SlingHttpServletRequest request, org.apache.sling.commons.json.JSONObject info, Resource resource)
    throws org.apache.sling.commons.json.JSONException {
  if (info.has(KEY_WORKFLOWS)) {
    final org.apache.sling.commons.json.JSONObject workflows = info.getJSONObject(KEY_WORKFLOWS);
    final String resourcePath = resource.getPath();
    final ResourceResolver resourceResolver = resource.getResourceResolver();
    for (final Iterator<String> types = workflows.keys(); types.hasNext();) {
      final String type = types.next();
      final org.apache.sling.commons.json.JSONObject typeObject = workflows.getJSONObject(type);
      filter(typeObject, resourcePath, resourceResolver);
    }
  } else {
    log.warn("No workflows found in existing page info. Check order of cq:infoProviders.");
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

try {
  boolean  b = false;
  Iterator<String> keys = jo.keys();
  writer.write('{');

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

JSONObject parsed = new JSONObject(value);
Map<String, String> columnMap = new HashMap<String, String>();
for (Iterator<String> iter = parsed.keys(); iter.hasNext();) {
  String key = iter.next();
  String innerValue = parsed.getString(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: org.apache.sling/org.apache.sling.commons.json

Iterator<String>     keys = o.keys();
String       s;
StringBuffer sb = new StringBuffer();

代码示例来源:origin: org.apache.sling/org.apache.sling.commons.json

keys = jo.keys();
while (keys.hasNext()) {
  k = keys.next();

代码示例来源: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: org.apache.sling/org.apache.sling.commons.json

Iterator<String> keys = jo.keys();
StringBuilder sb = new StringBuilder("{");
int newindent = opt.initialIndent + opt.indent;

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

final Iterator<String> keys = jsonObject.keys();

代码示例来源:origin: io.wcm/io.wcm.caconfig.editor

private ConfigurationPersistData parseConfigData(JSONObject item, ConfigurationMetadata configMetadata) throws JSONException {
 Map<String, Object> props = new HashMap<>();
 JSONObject properties = item.getJSONObject("properties");
 Iterator<String> propertyNames = properties.keys();
 while (propertyNames.hasNext()) {
  String propertyName = propertyNames.next();

代码示例来源: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;
}

相关文章