org.json.JSONArray.opt()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(270)

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

JSONArray.opt介绍

[英]Returns the value at index, or null if the array has no value at index.
[中]返回索引处的值,如果数组在索引处没有值,则返回null。

代码示例

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Get the optional JSONArray associated with an index.
 *
 * @param index
 *            subscript
 * @return A JSONArray value, or null if the index has no value, or if the
 *         value is not a JSONArray.
 */
public JSONArray optJSONArray(int index) {
  Object o = this.opt(index);
  return o instanceof JSONArray ? (JSONArray) o : null;
}

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Get the optional JSONObject associated with an index. Null is returned if
 * the key is not found, or null if the index has no value, or if the value
 * is not a JSONObject.
 *
 * @param index
 *            The index must be between 0 and length() - 1.
 * @return A JSONObject value.
 */
public JSONObject optJSONObject(int index) {
  Object o = this.opt(index);
  return o instanceof JSONObject ? (JSONObject) o : null;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is a {@code
 * JSONArray}. Returns null otherwise.
 */
public JSONArray optJSONArray(int index) {
  Object object = opt(index);
  return object instanceof JSONArray ? (JSONArray) object : null;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is a {@code
 * JSONObject}. Returns null otherwise.
 */
public JSONObject optJSONObject(int index) {
  Object object = opt(index);
  return object instanceof JSONObject ? (JSONObject) object : null;
}

代码示例来源:origin: apache/geode

/**
 * Returns the value at {@code index} if it exists and is a {@code
 * JSONArray}. Returns null otherwise.
 *
 * @param index Which value to get.
 * @return the value at the specified location.
 */
public JSONArray optJSONArray(int index) {
 Object object = opt(index);
 return object instanceof JSONArray ? (JSONArray) object : null;
}

代码示例来源:origin: apache/geode

/**
 * Returns true if this array has no value at {@code index}, or if its value is the {@code null}
 * reference or {@link JSONObject#NULL}.
 *
 * @param index Which value to check.
 * @return true if the value is null.
 */
public boolean isNull(int index) {
 Object value = opt(index);
 return value == null || value == JSONObject.NULL;
}

代码示例来源:origin: apache/geode

/**
 * Returns the value at {@code index} if it exists and is a {@code
 * JSONObject}. Returns null otherwise.
 *
 * @param index Which value to get.
 * @return the value at the specified location.
 */
public JSONObject optJSONObject(int index) {
 Object object = opt(index);
 return object instanceof JSONObject ? (JSONObject) object : null;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns true if this array has no value at {@code index}, or if its value
 * is the {@code null} reference or {@link JSONObject#NULL}.
 */
public boolean isNull(int index) {
  Object value = opt(index);
  return value == null || value == JSONObject.NULL;
}

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Determine if the value is null.
 *
 * @param index
 *            The index must be between 0 and length() - 1.
 * @return true if the value at the index is null, or if there is no value.
 */
public boolean isNull(int index) {
  return JSONObject.NULL.equals(this.opt(index));
}

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Get the optional string associated with an index. The defaultValue is
 * returned if the key is not found.
 *
 * @param index
 *            The index must be between 0 and length() - 1.
 * @param defaultValue
 *            The default value.
 * @return A String value.
 */
public String optString(int index, String defaultValue) {
  Object object = this.opt(index);
  return JSONObject.NULL.equals(object) ? defaultValue : object
      .toString();
}

代码示例来源:origin: ACRA/acra

@NonNull
  private static String[] jsonArrayToList(@Nullable JSONArray array) {
    final List<String> list = new ArrayList<>();
    if (array != null) {
      final int length = array.length();
      for (int i = 0; i < length; i++) {
        list.add(String.valueOf(array.opt(i)));
      }
    }
    return list.toArray(new String[list.size()]);
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is a long or
 * can be coerced to a long. Returns {@code fallback} otherwise.
 */
public long optLong(int index, long fallback) {
  Object object = opt(index);
  Long result = JSON.toLong(object);
  return result != null ? result : fallback;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is a double or can
 * be coerced to a double. Returns {@code fallback} otherwise.
 */
public double optDouble(int index, double fallback) {
  Object object = opt(index);
  Double result = JSON.toDouble(object);
  return result != null ? result : fallback;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is a boolean or can
 * be coerced to a boolean. Returns {@code fallback} otherwise.
 */
public boolean optBoolean(int index, boolean fallback) {
  Object object = opt(index);
  Boolean result = JSON.toBoolean(object);
  return result != null ? result : fallback;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists and is an int or
 * can be coerced to an int. Returns {@code fallback} otherwise.
 */
public int optInt(int index, int fallback) {
  Object object = opt(index);
  Integer result = JSON.toInteger(object);
  return result != null ? result : fallback;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the value at {@code index} if it exists, coercing it if
 * necessary. Returns {@code fallback} if no such value exists.
 */
public String optString(int index, String fallback) {
  Object object = opt(index);
  String result = JSON.toString(object);
  return result != null ? result : fallback;
}

代码示例来源:origin: apache/geode

/**
 * Returns the value at {@code index} if it exists and is a boolean or can be coerced to a
 * boolean. Returns {@code fallback} otherwise.
 *
 * @param index Which value to get.
 * @param fallback the fallback value to return if no value exists.
 * @return the value at the specified location or the fallback value.
 */
public boolean optBoolean(int index, boolean fallback) {
 Object object = opt(index);
 Boolean result = JSON.toBoolean(object);
 return result != null ? result : fallback;
}

代码示例来源:origin: apache/geode

/**
 * Returns the value at {@code index} if it exists and is a long or can be coerced to a long.
 * Returns {@code fallback} otherwise.
 *
 * @param index Which value to get.
 * @param fallback The fallback value to use if no value is at the specified location.
 * @return the value at the specified location or the fallback value.
 */
public long optLong(int index, long fallback) {
 Object object = opt(index);
 Long result = JSON.toLong(object);
 return result != null ? result : fallback;
}

代码示例来源:origin: apache/geode

/**
 * Returns the value at {@code index} if it exists, coercing it if necessary. Returns
 * {@code fallback} if no such value exists.
 *
 * @param index Which value to get.
 * @param fallback The fallback value to use if no value is at the specified location.
 * @return the value at the specified location or the fallback value.
 */
public String optString(int index, String fallback) {
 Object object = opt(index);
 String result = JSON.toString(object);
 return result != null ? result : fallback;
}

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Get the object value associated with an index.
 *
 * @param index
 *            The index must be between 0 and length() - 1.
 * @return An object value.
 * @throws JSONException
 *             If there is no value for the index.
 */
public Object get(int index) throws JSONException {
  Object object = this.opt(index);
  if (object == null) {
    throw new JSONException("JSONArray[" + index + "] not found.");
  }
  return object;
}

相关文章