net.minidev.json.JSONArray.toArray()方法的使用及代码示例

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

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

JSONArray.toArray介绍

暂无

代码示例

代码示例来源:origin: com.nimbusds/nimbus-jose-jwt

/**
 * Gets a string array member of a JSON object.
 *
 * @param o   The JSON object. Must not be {@code null}.
 * @param key The JSON object member key. Must not be {@code null}.
 *
 * @return The JSON object member value, may be {@code null}.
 *
 * @throws ParseException If the value is not of the expected type.
 */
public static String[] getStringArray(final JSONObject o, final String key)
    throws ParseException {
  JSONArray jsonArray = getJSONArray(o, key);
  
  if (jsonArray == null) {
    return null;
  }
  try {
    return jsonArray.toArray(new String[0]);
  } catch (ArrayStoreException e) {
    throw new ParseException("JSON object member with key \"" + key + "\" is not an array of strings", 0);
  }
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components

private boolean arrayMatched(JSONArray value) {
  if (value.isEmpty() && "[]".equals(getExpectedValue())) {
    return true;
  }
  for (Object subj : value.toArray()) {
    if ((subj == null && isExpectNull()) ||
        isEquals(subj)) {
      return true;
    }
  }
  return isEquals(value);
}

代码示例来源:origin: undera/jmeter-plugins

private boolean arrayMatched(JSONArray value) {
  if (value.isEmpty() && getExpectedValue().equals("[]")) {
    return true;
  }
  for (Object subj : value.toArray()) {
    if (isExpectNull() && subj == null) {
      return true;
    } else if (isEquals(subj)) {
      return true;
    }
  }
  return isEquals(value);
}

代码示例来源:origin: com.nimbusds/infinispan-sql-cache-store

/**
 * Parses a string array from the specified SQL record field.
 *
 * @param fieldName The SQL field name. Must not be {@code null}.
 * @param sqlRecord The SQL record. Must not be {@code null}.
 *
 * @return The string array, {@code null} if not specified.
 */
public String[] parseSQLStringCollection(final String fieldName, final Record sqlRecord) {
  
  if (CollectionDataType.ARRAY.equals(collectionDataType)) {
    
    // Expect SQL array
    return sqlRecord.get(fieldName, String[].class);
    
  } else {
    // Expect JSON array string
    String s = sqlRecord.get(fieldName, String.class);
    
    if (s == null) return null;
    
    try {
      JSONArray jsonArray = (JSONArray) JSONValue.parseStrict(s);
      return jsonArray.toArray(new String[]{});
    } catch (ParseException | ClassCastException e) {
      throw new PersistenceException("Couldn't parse JSON array: " + e.getMessage(), e);
    }
  }
}

代码示例来源:origin: kg.apc/jmeter-plugins-extras-libs

private void doAssert(String jsonString) {
  Object value = JsonPath.read(jsonString, getJsonPath());
  if (isJsonValidationBool()) {
    if (value instanceof JSONArray) {
      JSONArray arr = (JSONArray) value;
      if (arr.isEmpty() && getExpectedValue().equals("[]")) {
        return;
      }
      for (Object subj : arr.toArray()) {
        if (isExpectNull() && subj == null) {
          return;
        } else if (isEquals(subj.toString())) {
          return;
        }
      }
    } else {
      if (isExpectNull() && value == null) {
        return;
      } else if (isEquals(value.toString())) {
        return;
      }
    }
    if (isExpectNull())
      throw new RuntimeException(String.format("Value expected to be null, but found '%s'", value));
    else
      throw new RuntimeException(String.format("Value expected to be '%s', but found '%s'", getExpectedValue(), value));
  }
}

代码示例来源:origin: com.nimbusds/infinispan-cachestore-sql

/**
 * Parses a string array from the specified SQL record field.
 *
 * @param fieldName The SQL field name. Must not be {@code null}.
 * @param sqlRecord The SQL record. Must not be {@code null}.
 *
 * @return The string array, {@code null} if not specified.
 */
public String[] parseSQLStringCollection(final String fieldName, final Record sqlRecord) {
  
  if (CollectionDataType.ARRAY.equals(collectionDataType)) {
    
    // Expect SQL array
    return sqlRecord.get(fieldName, String[].class);
    
  } else {
    // Expect JSON array string
    String s = sqlRecord.get(fieldName, String.class);
    
    if (s == null) return null;
    
    try {
      JSONArray jsonArray = (JSONArray) JSONValue.parseStrict(s);
      return jsonArray.toArray(new String[]{});
    } catch (ParseException | ClassCastException e) {
      throw new PersistenceException("Couldn't parse JSON array: " + e.getMessage(), e);
    }
  }
}

代码示例来源:origin: salyh/elasticsearch-security-plugin

dlsPerm.addReadTokens(ja.toArray(new String[0]));
dlsPerm.addUpdateTokens(ja.toArray(new String[0]));
dlsPerm.addDeleteTokens(ja.toArray(new String[0]));

代码示例来源:origin: kg.apc/jmeter-plugins-extras-libs

Object jsonPathResult = JsonPath.read(responseData, getJsonPath());
if (jsonPathResult instanceof JSONArray) {
  Object[] arr = ((JSONArray) jsonPathResult).toArray();

代码示例来源:origin: undera/jmeter-plugins

Object[] arr = ((JSONArray) jsonPathResult).toArray();

相关文章