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

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

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

JSONArray.get介绍

[英]Get the object value associated with an index.
[中]获取与索引关联的对象值。

代码示例

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

/**
 * Get the long value associated with an index.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The value.
 * @throws   JSONException If the key is not found or if the value cannot
 *  be converted to a number.
 */
public long getLong(int index) throws JSONException {
  Object o = get(index);
  return o instanceof Number ?
      ((Number)o).longValue() : (long)getDouble(index);
}

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

/**
 * Get the string associated with an index.
 * @param index The index must be between 0 and length() - 1.
 * @return      A string value.
 * @throws JSONException If there is no value for the index.
 */
public String getString(int index) throws JSONException {
  return get(index).toString();
}

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

/**
 * Get the double value associated with an index.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The value.
 * @throws   JSONException If the key is not found or if the value cannot
 *  be converted to a number.
 */
public double getDouble(int index) throws JSONException {
  Object o = get(index);
  try {
    return o instanceof Number ?
      ((Number)o).doubleValue() :
      Double.valueOf((String)o).doubleValue();
  } catch (Exception e) {
    throw new JSONException("JSONArray[" + index +
      "] is not a number.");
  }
}

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

/**
 * Get the int value associated with an index.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The value.
 * @throws   JSONException If the key is not found or if the value cannot
 *  be converted to a number.
 *  if the value cannot be converted to a number.
 */
public int getInt(int index) throws JSONException {
  Object o = get(index);
  return o instanceof Number ?
      ((Number)o).intValue() : (int)getDouble(index);
}

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

/**
 * Get the boolean value associated with an index.
 * The string values "true" and "false" are converted to boolean.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The truth.
 * @throws JSONException If there is no value for the index or if the
 *  value is not convertable to boolean.
 */
public boolean getBoolean(int index) throws JSONException {
  Object o = get(index);
  if (o.equals(Boolean.FALSE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("false"))) {
    return false;
  } else if (o.equals(Boolean.TRUE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("true"))) {
    return true;
  }
  throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
}

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

/**
 * Make a string from the contents of this JSONArray. The
 * <code>separator</code> string is inserted between each element.
 * Warning: This method assumes that the data structure is acyclical.
 * @param separator A string that will be inserted between the elements.
 * @return a string.
 * @throws JSONException If the array contains an invalid number.
 */
public String join(JSONArray ja, String separator) throws JSONException {
  final int len = ja.length();
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < len; i += 1) {
    if (i > 0) {
      sb.append(separator);
    }
    sb.append(JSONObject.valueToString(ja.get(i)));
  }
  return sb.toString();
}

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

StringBuilder sb = new StringBuilder("[");
if (len == 1) {
  sb.append(valueToString(ja.get(0), opt));
} else {
  final int newindent = opt.initialIndent + opt.indent;
    sb.append(valueToString(ja.get(i), opt));

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

writer.write(',');
final Object v = ja.get(i);
if (v instanceof JSONObject) {
  ((JSONObject)v).write(writer);

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

/**
 * Get the JSONObject associated with an index.
 * @param index subscript
 * @return      A JSONObject value.
 * @throws JSONException If there is no value for the index or if the
 * value is not a JSONObject
 */
public JSONObject getJSONObject(int index) throws JSONException {
  Object o = get(index);
  if (o instanceof JSONObject) {
    return (JSONObject) o;
  } else if (o instanceof String) {
    JSONTokener tokener = new JSONTokener((String) o);
    try {
      return new JSONObject(tokener);
    } catch (JSONException ignore) {
      // will throw the appropriate exception below
    }
  }
  throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
}

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

/**
 * Get the JSONArray associated with an index.
 * @param index The index must be between 0 and length() - 1.
 * @return      A JSONArray value.
 * @throws JSONException If there is no value for the index. or if the
 * value is not a JSONArray
 */
public JSONArray getJSONArray(int index) throws JSONException {
  Object o = get(index);
  if (o instanceof JSONArray) {
    return (JSONArray) o;
  } else if (o instanceof String) {
    JSONTokener tokener = new JSONTokener((String) o);
    try {
      return new JSONArray(tokener);
    } catch (JSONException ignore) {
      // will throw the appropriate exception below
    }
  }
  throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
}

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

b.append('\n');
    b.append(escape(ja.get(i).toString()));
len = ja.length();
for (i = 0; i < len; i += 1) {
  b.append(toString(ja.get(i), k));

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

if (values.get(0) instanceof Integer) {
 props.put(propertyName, toArray(properties, propertyName, int.class));
else if (values.get(0) instanceof Long) {
 props.put(propertyName, toArray(properties, propertyName, long.class));
else if (values.get(0) instanceof Double) {
 props.put(propertyName, toArray(properties, propertyName, double.class));
else if (values.get(0) instanceof Boolean) {
 props.put(propertyName, toArray(properties, propertyName, boolean.class));

代码示例来源:origin: io.wcm/io.wcm.testing.sling-mock

final Object[] values = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
 values[i] = array.get(i);

相关文章