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

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

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

JSONArray.optString介绍

[英]Get the optional string value associated with an index. It returns an empty string if there is no value at that index. If the value is not a string and is not null, then it is coverted to a string.
[中]获取与索引关联的可选字符串值。如果该索引处没有值,则返回空字符串。如果值不是字符串且不为null,则将其转换为字符串。

代码示例

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the optional string value associated with an index. It returns an
 * empty string if there is no value at that index. If the value
 * is not a string and is not null, then it is coverted to a string.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      A String value.
 */
public String optString(int index) {
  return optString(index, "");
}

代码示例来源:origin: org.codehaus.jettison/com.springsource.org.codehaus.jettison

/**
 * Get the optional string value associated with an index. It returns an
 * empty string if there is no value at that index. If the value
 * is not a string and is not null, then it is coverted to a string.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      A String value.
 */
public String optString(int index) {
  return optString(index, "");
}

代码示例来源:origin: com.tinkerpop.rexster/rexster-core

/**
 * Given an array of keys from the request object, return the desired returnKeys.
 * <p/>
 * Useful for when the return keys are being passed in as a parameter to an extension method.
 *
 * @param arrayOfKeys array of keys from the request object.
 * @param wildcard    a value that represents the specification of all keys
 * @return the return keys
 */
public static Set<String> getReturnKeys(final JSONArray arrayOfKeys, final String wildcard) {
  Set<String> returnKeys = null;
  if (arrayOfKeys != null) {
    returnKeys = new HashSet<String>();
    for (int ix = 0; ix < arrayOfKeys.length(); ix++) {
      returnKeys.add(arrayOfKeys.optString(ix));
    }
    if (returnKeys.size() == 1 && returnKeys.contains(wildcard)) {
      returnKeys = null;
    }
  } else {
    returnKeys = null;
  }
  return returnKeys;
}

代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph

public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
  final String c = getKeyIndexClass(elementClass);
  final JSONArray jsonArray = RestHelper.getResultArray(this.graphURI + RexsterTokens.SLASH_KEY_INDICES_SLASH + c);
  final HashSet<String> keys = new HashSet<String>();
  for (int ix = 0; ix < jsonArray.length(); ix++) {
    keys.add(jsonArray.optString(ix));
  }
  return keys;
}

代码示例来源:origin: com.tinkerpop.rexster/rexster-core

final StringBuffer sb = new StringBuffer();
for (int ix = 0; ix < propertyArray.length(); ix++) {
  sb.append(propertyArray.optString(ix));

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

public static enum TYPE_STRICT {any,all,should};

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

private static Constraint parseSimilarityConstraint(JSONObject jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
  String context = jConstraint.optString("context");
  if(context == null){
    throw new IllegalArgumentException("SimilarityConstraints MUST define a \"context\": \n "+jConstraint.toString(4));
  }
  JSONArray addFields = jConstraint.optJSONArray("addFields");
  final List<String> fields;
  if(addFields != null && addFields.length() > 0){
    fields = new ArrayList<String>(addFields.length());
    for(int i=0;i<addFields.length();i++){
      String field = addFields.optString(i);
      field = field != null ? nsPrefixService.getFullName(field) : null;
      if(field != null && !field.isEmpty()){
        fields.add(field);
      }
    }
  } else {
    fields = null;
  }
  return new SimilarityConstraint(context,fields);
}

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

/**
 * Asserts that the selected JSONArray of the field query returned within
 * the result list contains parsed selected fields
 * @param jQuery the query e.g. as returned by 
 * {@link #assertQueryResults(RequestExecutor, QueryTestCase)}
 * @return the selected fields for further processing
 * @throws JSONException on any error while parsing the JSON
 */
public static JSONArray assertSelectedField(JSONObject jQuery,String...selected) throws JSONException {
  Set<String> selectedSet = new HashSet<String>();
  if(selected == null || selected.length == 0) {
    selectedSet = Collections.emptySet();
  } else {
    selectedSet = new HashSet<String>(Arrays.asList(selected));
  }
  JSONArray jSelected = jQuery.optJSONArray("selected");
  assertNotNull("Result Query is missing the 'selected' property",jSelected);
  assertTrue("Result Query is expected to have at least a single selected field",
    jSelected.length() > 0);
  boolean found = false;
  for(int i=0;i<jSelected.length() && !found;i++){
    String selectedField = jSelected.optString(i,null);
    assertNotNull("Selected array contains a NULL element \n"+jSelected.toString(4),
      selectedField);
    selectedSet.remove(selectedField);
  }
  assertTrue("Fields "+selectedSet+" are not selected by\n"+jSelected.toString(4),
    selectedSet.isEmpty());
  return jSelected;
}

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

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

JSONObject fieldValue = jValues.optJSONObject(i);
assertNotNull("Values for field "+key+" does contain an value " +
    "that is not an JSONObject "+jValues.optString(i),
    fieldValue);
String[] value = new String[2];

代码示例来源:origin: dbs-leipzig/gradoop

String stringValue = listOrObject ? array.optJSONObject(i).toString() : array.optString(i);

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);
List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
    for (int i = 0; i < jsonArray.length(); i++) {
      String value = jsonArray.optString(i);
      if (value != null) {
        values.add(value);
    List<String> values = new ArrayList<String>();
    for (int i = 0; i < jsonArray.length(); i++) {
      String value = jsonArray.optString(i);
      if (value != null) {
        values.add(value);
List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

if (jsonArray != null) {
  for (int i = 0; i < jsonArray.length(); i++) {
    String value = jsonArray.optString(i);
    if (value != null) {
      values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);
List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);
List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

if (jsonArray != null) {
  for (int i = 0; i < jsonArray.length(); i++) {
    String value = jsonArray.optString(i);
    if (value != null) {
      values.add(value);

代码示例来源:origin: GluuFederation/oxAuth

List<String> values = new ArrayList<String>();
  for (int i = 0; i < jsonArray.length(); i++) {
    String value = jsonArray.optString(i);
    if (value != null) {
      values.add(value);
List<String> values = new ArrayList<String>();
for (int i = 0; i < jsonArray.length(); i++) {
  String value = jsonArray.optString(i);
  if (value != null) {
    values.add(value);

相关文章