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

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

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

JSONObject.getString介绍

[英]Get the string associated with a 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: org.apache.sling/org.apache.sling.commons.json

StringBuffer sb = new StringBuffer();
if (o.has("Status-Code") && o.has("Reason-Phrase")) {
  sb.append(o.getString("HTTP-Version"));
  sb.append(' ');
  sb.append(o.getString("Status-Code"));
  sb.append(' ');
  sb.append(o.getString("Reason-Phrase"));
} else if (o.has("Method") && o.has("Request-URI")) {
  sb.append(o.getString("Method"));
  sb.append(' ');
  sb.append('"');
  sb.append(o.getString("Request-URI"));
  sb.append('"');
  sb.append(' ');
  sb.append(o.getString("HTTP-Version"));
} else {
  throw new JSONException("Not enough material for an HTTP header.");
    sb.append(s);
    sb.append(": ");
    sb.append(o.getString(s));
    sb.append(CRLF);

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

private Object toSingle(JSONObject properties, String propertyName, Class propertyType) throws JSONException {
 if (propertyType.equals(String.class)) {
  return properties.getString(propertyName);
 }
 else if (propertyType.equals(int.class)) {
  return properties.getInt(propertyName);
 }
 else if (propertyType.equals(long.class)) {
  return properties.getLong(propertyName);
 }
 else if (propertyType.equals(double.class)) {
  return properties.getDouble(propertyName);
 }
 else if (propertyType.equals(boolean.class)) {
  return properties.getBoolean(propertyName);
 }
 else {
  throw new IllegalArgumentException("Unexpected type: " + propertyType.getName());
 }
}

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

StringBuffer sb = new StringBuffer();
sb.append(escape(o.getString("name")));
sb.append("=");
sb.append(escape(o.getString("value")));
if (o.has("expires")) {
  sb.append(";expires=");
  sb.append(o.getString("expires"));
  sb.append(escape(o.getString("domain")));
  sb.append(escape(o.getString("path")));

代码示例来源:origin: otros-systems/otroslogviewer

@Override
 public Optional<List<Session>> deserialize(String data) {
  final ArrayList<Session> sessions = new ArrayList<>();
  try {
   final JSONArray array = new JSONArray(data);
   for (int i = 0; i < array.length(); i++) {
    final JSONObject jsonObject = array.getJSONObject(i);
    String name = jsonObject.getString("name");
    final ArrayList<FileToOpen> fileToOpens = new ArrayList<>();
    final JSONArray filesArray = jsonObject.optJSONArray("filesToOpen");
    if (filesArray != null){
     for (int j = 0; j < filesArray.length(); j++) {
      final JSONObject filesToOpen = filesArray.getJSONObject(j);
      String uri = filesToOpen.getString("uri");
      Level level = Level.parse(filesToOpen.getString("level"));
      OpenMode openMode = OpenMode.valueOf(filesToOpen.getString("openMode"));
      String logImporter = filesToOpen.optString("logImporter", null);
      fileToOpens.add(new FileToOpen(uri, openMode, level, Optional.ofNullable(logImporter)));
     }
    }
    sessions.add(new Session(name, fileToOpens));
   }
  } catch (JSONException e) {
   LOGGER.error("Can't deserialize sessions: ", e);
   Optional.empty();
  }
  LOGGER.info("Returning deserialized sessions: " + sessions.size());
  return Optional.of(sessions);
 }
}

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

public Parameters(SlingHttpServletRequest request) throws IOException, JSONException {
  final JSONObject json = new JSONObject(request.getParameter("params"));
  final List<String> customProperties = new ArrayList<String>();
  final List<String> groups = new ArrayList<String>();
  groupFilter = json.getString(GROUP_FILTER);
  JSONArray groupsJSON = json.getJSONArray(GROUPS);
  for (int i = 0; i < groupsJSON.length(); i++) {
    groups.add(groupsJSON.getString(i));
  }
  this.groups = groups.toArray(new String[groups.size()]);
  JSONArray customPropertiesJSON = json.getJSONArray(CUSTOM_PROPERTIES);
  for (int i = 0; i < customPropertiesJSON.length(); i++) {
    JSONObject tmp = customPropertiesJSON.getJSONObject(i);
    String relativePropertyPath = tmp.optString(RELATIVE_PROPERTY_PATH);
    if (StringUtils.isNotBlank(relativePropertyPath)) {
      customProperties.add(relativePropertyPath);
    }
  }
  this.customProperties = customProperties.toArray(new String[customProperties.size()]);
}

代码示例来源:origin: otros-systems/otroslogviewer

try {
 final JSONObject o = a.getJSONObject(i);
 final String searchMde = o.getString(SEARCH_MODE);
 final String query = o.getString(QUERY);
 searchHistories.add(new SearchHistory(SearchAction.SearchMode.valueOf(searchMde), query));
} catch (Exception e) {

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

for (Iterator<String> iter = parsed.keys(); iter.hasNext();) {
  String key = iter.next();
  String innerValue = parsed.getString(key);
  columnMap.put(key, innerValue);

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

@Override
public String startTranscriptionJob(InputStream stream, String mimeType) {
  Request request = httpClientFactory.post("/speech-to-text/api/v1/recognitions?continuous=true&timestamps=true").
      addHeader("Content-Type", mimeType).
      bodyStream(stream);
  try {
    JSONObject json = httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);
    log.trace("content: {}", json.toString(2));
    return json.getString("id");
  } catch (Exception e) {
    log.error("error submitting job", e);
    return null;
  }
}

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

private void handleCommand(JSONObject obj, ChannelHandlerContext ctx) throws JSONException {
  String cmd = obj.getString(COMMAND);
  Channel channel = ctx.channel();
  if (CMD_HELLO.equals(cmd)) {
    ChannelInfo info = infos.get(channel);
    if (info != null) {
      String url = obj.getString(URL);
      try {
        URI uri = new URI(url);

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

private void handleCommand(JSONObject obj, ChannelHandlerContext ctx) throws JSONException {
  String cmd = obj.getString(COMMAND);
  Channel channel = ctx.channel();
  if (CMD_HELLO.equals(cmd)) {
    ChannelInfo info = infos.get(channel);
    if (info != null) {
      String url = obj.getString(URL);
      try {
        URI uri = new URI(url);

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

if (json.getString("status").equals("completed")) {
  JSONArray results = json.getJSONArray("results").getJSONObject(0).getJSONArray("results");
  StringBuilder builder = new StringBuilder();
    if (result.getBoolean("final")) {
      JSONObject firstAlternative = result.getJSONArray("alternatives").getJSONObject(0);
      String line = firstAlternative.getString("transcript");
      if (StringUtils.isNotBlank(line)) {
        double firstTimestamp = firstAlternative.getJSONArray("timestamps").getJSONArray(0).getDouble(1);

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

collectionItemName = item.getString("collectionItemName");

代码示例来源:origin: streampipes/streampipes-ce

for (int i = 0; i < data.length(); i++) {
 JSONObject object = data.getJSONObject(i);
 options.add(new Option(object.getString(value)));

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

@SuppressWarnings("squid:S3776")
private void filter(org.apache.sling.commons.json.JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) 
    throws org.apache.sling.commons.json.JSONException {
  final org.apache.sling.commons.json.JSONArray models = typeObject.getJSONArray(KEY_MODELS);
  final org.apache.sling.commons.json.JSONArray newModels = new org.apache.sling.commons.json.JSONArray();
  for (int i = 0; i < models.length(); i++) {
    final org.apache.sling.commons.json.JSONObject modelObject = models.getJSONObject(i);
    final String path = modelObject.getString(KEY_MODEL_PATH);
    final Resource modelResource = resourceResolver.getResource(path);
    if (modelResource != null) {
      // we're looking for the appliesTo property on the jcr:content node, the wid value
      // is the path to the jcr:content/model node.
      final ValueMap properties = modelResource.getParent().getValueMap();
      final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
      if (allowedPaths == null) {
        newModels.put(modelObject);
      } else {
        for (final String allowedPath : allowedPaths) {
          if (resourcePath.matches(allowedPath)) {
            newModels.put(modelObject);
            break;
          }
        }
      }
    }
  }
  
  typeObject.put(KEY_MODELS, newModels);
}

代码示例来源:origin: org.streampipes/streampipes-pipeline-management

for (int i = 0; i < data.length(); i++) {
 JSONObject object = data.getJSONObject(i);
 options.add(new Option(object.getString(value)));

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

private void filter(JSONObject typeObject, String resourcePath, ResourceResolver resourceResolver) throws JSONException {
  final JSONArray models = typeObject.getJSONArray(KEY_MODELS);
  final JSONArray newModels = new JSONArray();
  for (int i = 0; i < models.length(); i++) {
    final JSONObject modelObject = models.getJSONObject(i);
    final String path = modelObject.getString(KEY_MODEL_PATH);
    final Resource modelResource = resourceResolver.getResource(path);
    if (modelResource != null) {
      // we're looking for the appliesTo property on the jcr:content node, the wid value
      // is the path to the jcr:content/model node.
      final ValueMap properties = modelResource.getParent().getValueMap();
      final String[] allowedPaths = properties.get(PN_ALLOWED_PATHS, String[].class);
      if (allowedPaths == null) {
        newModels.put(modelObject);
      } else {
        for (final String allowedPath : allowedPaths) {
          if (resourcePath.matches(allowedPath)) {
            newModels.put(modelObject);
            break;
          }
        }
      }
    }
  }
  
  typeObject.put(KEY_MODELS, newModels);
}

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

final ModifiableValueMap properties = request.getResource().adaptTo(ModifiableValueMap.class);
properties.put("runnerType", params.getString("runnerType"));
properties.put("queryType", params.getString("queryType"));
properties.put("queryStatement", params.getString("queryStatement"));
properties.put("relativePath", StringUtils.removeStart(params.optString("relativePath", ""), "/"));
properties.put("workflowModel", params.getString("workflowModelId"));
properties.put("interval", params.optInt("interval", 10));
properties.put("timeout", params.optInt("timeout", 30));

相关文章