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

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

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

JSONObject.put介绍

[英]Put a key/double pair in the JSONObject.
[中]在JSONObject中放置一个密钥/双精度对。

代码示例

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

/**
 * Put a key/boolean pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A boolean which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(String key, boolean value) throws JSONException {
  put(key, value ? Boolean.TRUE : Boolean.FALSE);
  return this;
}

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

private JSONObject createReloadObject(String includePath) throws JSONException {
  JSONObject reload = new JSONObject();
  reload.put(COMMAND, CMD_RELOAD);
  reload.put(PATH, includePath);
  reload.put("liveCSS", true);
  return reload;
}

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

/**
 * Put a key/int pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value An int which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(String key, int value) throws JSONException {
  put(key, new Integer(value));
  return this;
}

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

private JSONObject createReloadObject(String includePath) throws JSONException {
  JSONObject reload = new JSONObject();
  reload.put(COMMAND, CMD_RELOAD);
  reload.put(PATH, includePath);
  reload.put("liveCSS", true);
  return reload;
}

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

/**
 * Put a key/double pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A double which is the value.
 * @return this.
 * @throws JSONException If the key is null or if the number is invalid.
 */
public JSONObject put(String key, double value) throws JSONException {
  put(key, new Double(value));
  return this;
}

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

private void addMessage(JSONObject jsonObject, String message) {
  try {
    jsonObject.put("message", message);
  } catch (JSONException e) {
    log.error("Could not formulate JSON Response", e);
  }
}

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

/**
 * Put a key/long pair in the JSONObject.
 *
 * @param key   A key string.
 * @param value A long which is the value.
 * @return this.
 * @throws JSONException If the key is null.
 */
public JSONObject put(String key, long value) throws JSONException {
  put(key, new Long(value));
  return this;
}

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

@Override
protected JSONObject createEmptyWidget(String rteName) throws JSONException {
  JSONObject object = new JSONObject();
  object.put("xtype", "richtext");
  object.put("name", "./" + xssApi.encodeForJSString(rteName));
  object.put("hideLabel", true);
  object.put("jcr:primaryType", "cq:Widget");
  return object;
}

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

@Override
protected JSONObject createEmptyWidget(String propertyName) throws JSONException {
  JSONObject object = new JSONObject();
  object.put("xtype", "tags");
  object.put("name", "./" + xssApi.encodeForJSString(propertyName));
  object.put("fieldLabel", "Tags/Keywords");
  object.put("jcr:primaryType", "cq:Widget");
  return object;
}

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

private void addActionManagerTrackedCounts(String name, JSONObject json) throws JSONException {
  final ActionManager actionManager = actionManagerFactory.getActionManager(name);
  int failureCount = actionManager.getErrorCount();
  int completeCount = actionManager.getSuccessCount();
  int totalCount = actionManager.getAddedCount();
  int remainingCount = actionManager.getRemainingCount();
  json.put("totalCount", totalCount);
  json.put("completeCount", completeCount);
  json.put("remainingCount", remainingCount);
  json.put("failCount", failureCount);
  json.put("percentComplete", Math.round(((totalCount - remainingCount) / (totalCount * 1F)) * DECIMAL_TO_PERCENT));
}

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

/**
 * Put a key/value pair in the JSONObject, where the value will be a
 * JSONArray which is produced from a Collection.
 * @param key     A key string.
 * @param value    A Collection value.
 * @return        this.
 * @throws JSONException
 */
public JSONObject put(String key, Collection<?> value) throws JSONException {
  put(key, new JSONArray(value));
  return this;
}

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

/**
 * Put a key/value pair in the JSONObject, where the value will be a
 * JSONObject which is produced from a Map.
 * @param key     A key string.
 * @param value    A Map value.
 * @return        this.
 * @throws JSONException
 */
public JSONObject put(String key, Map<String, ?> value) throws JSONException {
  put(key, new JSONObject(value));
  return this;
}

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

public JSONObject toJSON(final Action action) throws JSONException {

    final JSONObject json = new JSONObject();

    if (action != null) {
      json.put("uri", action.getUri());
      json.put("method", action.getMethod());
      json.put("target", action.getTarget());
      json.put("xhr", false);
      json.put("script", action.getScript());
      json.put("params", new JSONObject(action.getParams()));
    }

    return json;
  }
}

代码示例来源:origin: org.apache.flink/flink-streaming-java_2.10

private void decorateEdge(JSONArray inputArray, StreamEdge inEdge, int mappedInputID)
    throws JSONException {
  JSONObject input = new JSONObject();
  inputArray.put(input);
  input.put(ID, mappedInputID);
  input.put(SHIP_STRATEGY, inEdge.getPartitioner());
  input.put(SIDE, (inputArray.length() == 0) ? "first" : "second");
}

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

public JSONObject toJSON(final Result result, final ValueMap config) throws JSONException {
  final JSONObject json = new JSONObject();
  json.put("title", result.getTitle());
  json.put("type", result.getResultType());
  json.put("description", result.getDescription());
  json.put("path", result.getPath());
  json.put("action", this.toJSON(result.getAction()));
  json.put("secondaryAction", this.toJSON(result.getSecondaryAction()));
  return json;
}

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

private void addWorkspaceTrackedCounts(Workspace workspace, JSONObject json) throws JSONException {
  // Counts
  int remainingCount = workspace.getTotalCount() - (workspace.getCompleteCount() + workspace.getFailCount());
  json.put("totalCount", workspace.getTotalCount());
  json.put("completeCount", workspace.getCompleteCount());
  json.put("remainingCount", remainingCount);
  json.put("failCount", workspace.getFailCount());
  json.put("percentComplete", Math.round(((workspace.getTotalCount() - remainingCount) / (workspace.getTotalCount() * 1F)) * DECIMAL_TO_PERCENT));
}

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

private JSONArray convertResponseToJson(List<ReplicationResult> list) throws JSONException {
  JSONArray arr = new JSONArray();
  for (ReplicationResult result : list) {
    JSONObject resultObject = new JSONObject();
    resultObject.put("path", result.getPath());
    resultObject.put("status", result.getStatus().name());
    resultObject.put("version", result.getVersion());
    arr.put(resultObject);
  }
  return arr;
}

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

private void writeJsonResponse(final List<String> categories,
                final SlingHttpServletResponse response) throws JSONException, IOException {
  final JSONObject jsonObject = new JSONObject();
  jsonObject.put("categories", new JSONArray(categories));
  response.getWriter().print(jsonObject.toString());
}

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

/** Dump a single node */
private static void createSingleResource(final Resource n, final JSONObject parent,
    final int currentRecursionLevel, final int maxRecursionLevels)
    throws JSONException {
  if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
    parent.put(ResourceUtil.getName(n), create(n, currentRecursionLevel + 1, maxRecursionLevels));
  }
}

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

public JSONArray getCustomPropertiesAsJSON() throws JSONException {
  final JSONArray jsonArray = new JSONArray();
  for (String customProperty : customProperties) {
    final JSONObject jsonObject = new JSONObject();
    jsonObject.put(RELATIVE_PROPERTY_PATH, customProperty);
    jsonArray.put(jsonObject);
  }
  return jsonArray;
}

相关文章