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

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

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

JSONArray.toJSONString介绍

[英]Explicitely Serialize Object as JSon String
[中]将对象显式序列化为JSon字符串

代码示例

代码示例来源:origin: json-path/JsonPath

@Override
public String toJson(Object obj) {
  if (obj instanceof Map) {
    return JSONObject.toJSONString((Map<String, ?>) obj, JSONStyle.LT_COMPRESS);
  } else if (obj instanceof List) {
    return JSONArray.toJSONString((List<?>) obj, JSONStyle.LT_COMPRESS);
  } else {
    throw new UnsupportedOperationException(obj.getClass().getName() + " can not be converted to JSON");
  }
}

代码示例来源:origin: pinterest/secor

public void exportStats() throws Exception {
  List<Stat> stats = getStats();
  LOG.info("Stats: {}", JSONArray.toJSONString(stats));
  // if there is a valid openTSDB port configured export to openTSDB
  if (mConfig.getTsdbHostport() != null && !mConfig.getTsdbHostport().isEmpty()) {
    for (Stat stat : stats) {
      exportToTsdb(stat);
    }
  }
  // if there is a valid statsD port configured export to statsD
  if (mStatsDClient != null) {
    exportToStatsD(stats);
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public String toJson(Object obj) {
  if (obj instanceof Map) {
    return JSONObject.toJSONString((Map<String, ?>) obj, JSONStyle.LT_COMPRESS);
  } else if (obj instanceof List) {
    return JSONArray.toJSONString((List<?>) obj, JSONStyle.LT_COMPRESS);
  } else {
    throw new UnsupportedOperationException(obj.getClass().getName() + " can not be converted to JSON");
  }
}

代码示例来源:origin: net.minidev/json-smart

/**
 * JSONAwareEx inferface
 * 
 * @param compression
 *            compression param
 */
public String toString(JSONStyle compression) {
  return toJSONString(compression);
}

代码示例来源:origin: net.minidev/json-smart

/**
 * Override natif toStirng()
 */
public String toString() {
  return toJSONString();
}

代码示例来源:origin: netplex/json-smart-v2

/**
 * Override natif toStirng()
 */
public String toString() {
  return toJSONString();
}

代码示例来源:origin: net.minidev/json-smart

/**
 * Explicitely Serialize Object as JSon String
 */
public String toJSONString() {
  return toJSONString(this, JSONValue.COMPRESSION);
}

代码示例来源:origin: netplex/json-smart-v2

/**
 * Explicitely Serialize Object as JSon String
 */
public String toJSONString() {
  return toJSONString(this, JSONValue.COMPRESSION);
}

代码示例来源:origin: netplex/json-smart-v2

/**
 * JSONAwareEx inferface
 * 
 * @param compression
 *            compression param
 */
public String toString(JSONStyle compression) {
  return toJSONString(compression);
}

代码示例来源:origin: net.minidev/json-smart

public String toJSONString(JSONStyle compression) {
  return toJSONString(this, compression);
}

代码示例来源:origin: netplex/json-smart-v2

public static String toJSONString(List<? extends Object> list) {
  return toJSONString(list, JSONValue.COMPRESSION);
}

代码示例来源:origin: netplex/json-smart-v2

public String toJSONString(JSONStyle compression) {
  return toJSONString(this, compression);
}

代码示例来源:origin: net.minidev/json-smart

public static String toJSONString(List<? extends Object> list) {
  return toJSONString(list, JSONValue.COMPRESSION);
}

代码示例来源:origin: com.github.lafa.jsonpath/json-path

@Override
public String toJson(Object obj) {
  if (obj instanceof Map) {
    return JSONObject.toJSONString((Map<String, ?>) obj, JSONStyle.LT_COMPRESS);
  } else if (obj instanceof List) {
    return JSONArray.toJSONString((List<?>) obj, JSONStyle.LT_COMPRESS);
  } else {
    throw new UnsupportedOperationException(obj.getClass().getName() + " can not be converted to JSON");
  }
}

代码示例来源:origin: arago/rike

@Override
public String toJSONString() {
  List<T> all = resultToList();
  return JSONArray.toJSONString(all);
}

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

@SuppressWarnings("unchecked")
private String stringifyJSONObject(Object obj) {
  if (obj instanceof Map) {
    return new JSONObject((Map<String, ?>) obj).toJSONString();
  }
  if (obj instanceof JSONArray) {
    return ((JSONArray)obj).toJSONString();
  }
  return obj == null ? "" : obj.toString(); //$NON-NLS-1$
}

代码示例来源:origin: com.consol.citrus/citrus-core

/**
   * Evaluate JsonPath expression using given read context and return result as string.
   * @param readerContext
   * @param jsonPathExpression
   * @return
   */
  public static String evaluateAsString(ReadContext readerContext, String jsonPathExpression) {
    Object jsonPathResult = evaluate(readerContext, jsonPathExpression);

    if (jsonPathResult instanceof JSONArray) {
      return ((JSONArray) jsonPathResult).toJSONString();
    } else if (jsonPathResult instanceof JSONObject) {
      return ((JSONObject) jsonPathResult).toJSONString();
    } else {
      return Optional.ofNullable(jsonPathResult).map(Object::toString).orElse("null");
    }
  }
}

代码示例来源:origin: org.btrplace/scheduler-json

/**
 * Convert an array of VM identifiers to a set of VMs.
 * This operation uses a cache of previously converted set of VMs.
 * @param mo the associated model to browse
 * @param a the json array
 * @return the set of VMs
 */
public static List<VM> vmsFromJSON(Model mo, JSONArray a) throws JSONConverterException {
  String json = a.toJSONString();
  List<VM> s = vmsCache.get(json);
  if (s != null) {
    return s;
  }
  s = new ArrayList<>(a.size());
  for (Object o : a) {
    s.add(getVM(mo, (int) o));
  }
  vmsCache.put(json, s);
  return s;
}

代码示例来源:origin: btrplace/scheduler

/**
 * Convert an array of VM identifiers to a set of VMs.
 * This operation uses a cache of previously converted set of VMs.
 * @param mo the associated model to browse
 * @param a the json array
 * @return the set of VMs
 */
public static List<VM> vmsFromJSON(Model mo, JSONArray a) throws JSONConverterException {
  String json = a.toJSONString();
  List<VM> s = vmsCache.get(json);
  if (s != null) {
    return s;
  }
  s = new ArrayList<>(a.size());
  for (Object o : a) {
    s.add(getVM(mo, (int) o));
  }
  vmsCache.put(json, s);
  return s;
}

代码示例来源:origin: gradle.plugin.com.github.qwazer/markdown-confluence-gradle-plugin

private static String buildAddLabelsPostBody(Collection<String> labels) {
  if (labels==null || labels.isEmpty()) return null;
  JSONArray jsonArray = new JSONArray();
  for (String s : labels){
    if (s != null && !s.isEmpty()) {
      JSONObject label = new JSONObject();
      label.put("prefix", "global");
      label.put("name", s);
      jsonArray.add(label);
    }
  }
  return jsonArray.toJSONString();
}

相关文章