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

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

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

JSONArray.add介绍

暂无

代码示例

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

@Test
public void testPredicateWithFunctionCallTwoMatches() {
  String path = "$.batches.results[?(@.values.length() >= 3)].values.avg()";
  // Its an array because in some use-cases the min size might match more than one batch and thus we'll get
  // the average out for each collection
  JSONArray values = new JSONArray();
  values.add(12.2d);
  values.add(17d);
  verifyFunction(conf, path, BATCH_JSON, values);
}

代码示例来源:origin: networknt/light-4j

private static void maskList(DocumentContext ctx, String jsonPath, String expression) {
  ctx.configuration().addOptions(Option.AS_PATH_LIST);
  Configuration conf = Configuration.builder().options(Option.AS_PATH_LIST).build();
  DocumentContext context = JsonPath.using(conf).parse(ctx.jsonString());
  List<String> pathList = context.read(jsonPath);
  /**
   * when reach here, ctx.read(jsonPath) should only give us a list of strings so that we can replace with MASK_REPLACEMENT_CHAR
   * list of values can belongs to a same path or different paths, we should treat differently.
   * two situations:
   * an array contains multiple String values like: "list": ["ab", "cd", "ef]
   * or single value belongs to different paths.
   */
  if(pathList != null && pathList.size() == 1) {
    String path = pathList.get(0);
    List values = ctx.read(path);
    JSONArray maskedValue = new JSONArray();
    //mask each value in the list of the same path
    values.forEach(o -> maskedValue.add(replaceWithMask(o.toString(), MASK_REPLACEMENT_CHAR.charAt(0), expression)));
    ctx.set(path, maskedValue);
  } else {
    for (String path : Optional.ofNullable(pathList).orElse(Collections.emptyList())) {
      Object value = ctx.read(path);
      ctx.set(path, replaceWithMask(value.toString(), MASK_REPLACEMENT_CHAR.charAt(0), expression));
    }
  }
}

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

/**
 * The fictitious use-case/story - is we have a collection of batches with values indicating some quality metric.
 * We want to determine the average of the values for only the batch's values where the number of items in the batch
 * is greater than the min batch size which is encoded in the JSON document.
 *
 * We use the length function in the predicate to determine the number of values in each batch and then for those
 * batches where the count is greater than min we calculate the average batch value.
 *
 * Its completely contrived example, however, this test exercises functions within predicates.
 */
@Test
public void testPredicateWithFunctionCallSingleMatch() {
  String path = "$.batches.results[?(@.values.length() >= $.batches.minBatchSize)].values.avg()";
  // Its an array because in some use-cases the min size might match more than one batch and thus we'll get
  // the average out for each collection
  JSONArray values = new JSONArray();
  values.add(12.2d);
  verifyFunction(conf, path, BATCH_JSON, values);
}

代码示例来源:origin: NemProject/nem.core

private void pushLabel(final String label) {
  if (null == this.propertyOrderArray) {
    return;
  }
  this.propertyOrderArray.add(label);
}

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

/**
 * Appends the specified element and returns this.
 * Handy alternative to add(E e) method.
 *
 * @param element element to be appended to this array.
 * @return this
 */
public JSONArray appendElement(Object element) {
  add(element);
  return this;
}

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

/**
 * Appends the specified element and returns this.
 * Handy alternative to add(E e) method.
 *
 * @param element element to be appended to this array.
 * @return this
 */
public JSONArray appendElement(Object element) {
  add(element);
  return this;
}

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

@Override
public void addValue(Object current, Object value) {
  ((JSONArray) current).add(value);
}

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

@Override
public void addValue(Object current, Object value) {
  ((JSONArray) current).add(value);
}

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

protected static JSONArray merge(JSONArray o1, Object o2) {
  if (o2 == null)
    return o1;
  if (o1 instanceof JSONArray)
    return merge(o1, (JSONArray) o2);
  o1.add(o2);
  return o1;
}

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

protected static JSONArray merge(JSONArray o1, Object o2) {
  if (o2 == null)
    return o1;
  if (o1 instanceof JSONArray)
    return merge(o1, (JSONArray) o2);
  o1.add(o2);
  return o1;
}

代码示例来源:origin: net.sf.phat/phat-api-server

public static JSONArray getSymptoms(DiseaseManager dm) {
  JSONArray symptoms = new JSONArray();
  Iterator<Symptom> it = dm.getSymptoms().iterator();
  while (it.hasNext()) {
    symptoms.add(it.next());
  }
  return symptoms;
}

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

private void handleNewNode(TreePath jp, Object node) {
  if (!jp.hasPrev()) {
    return;
  }
  if (destNodeStack.peek() instanceof JSONObject) {
    ((JSONObject) destNodeStack.peek()).put(jp.curr(), node);
  } else if (destNodeStack.peek() instanceof JSONArray) {
    ((JSONArray) destNodeStack.peek()).add(node);
  }
  destNodeStack.push(node);
}

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

private void handleNewNode(TreePath jp, Object node) {
  if (!jp.hasPrev()) {
    return;
  }
  if (destNodeStack.peek() instanceof JSONObject) {
    ((JSONObject) destNodeStack.peek()).put(jp.curr(), node);
  } else if (destNodeStack.peek() instanceof JSONArray) {
    ((JSONArray) destNodeStack.peek()).add(node);
  }
  destNodeStack.push(node);
}

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

@Override
public JSONArray toJSON(Object c) {
  JSONArray a = new JSONArray();
  for (Object o : (Collection) c) {
    a.add(type.toJSON(o));
  }
  return a;
}

代码示例来源:origin: net.sf.phat/phat-api-server

public static JSONObject getJSON(String id, HouseType houseType, House house) {
  Map<String, Object> map = new HashMap<>();
  JSONArray roomsArray = new JSONArray();
  for (String rName : house.getRoomNames()) {
    roomsArray.add(rName);
  }
  map.put(PHATObjectToJSON.KEYS.rooms.name(), roomsArray);
  map.put(PHATObjectToJSON.KEYS.type.name(), houseType);
  map.put(PHATObjectToJSON.KEYS.name.name(), id);
  return new JSONObject(map);
}

代码示例来源:origin: org.geoserver.community/gs-oseo-rest

private JSONArray jsonArray(Object... values) {
  JSONArray array = new JSONArray();
  for (int i = 0; i < values.length; i++) {
    array.add(values[i]);
  }
  return array;
}

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

@Override
  public JSONObject toJSON(Split o) {
    JSONObject c = new JSONObject();
    c.put("id", getJSONId());

    JSONArray a = new JSONArray();
    for (Collection<VM> grp : o.getSets()) {
      a.add(vmsToJSON(grp));
    }

    c.put("parts", a);
    c.put("continuous", o.isContinuous());
    return c;
  }
}

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

@Override
public JSONObject toJSON(ReconfigurationPlan plan) throws JSONConverterException {
  JSONObject ob = new JSONObject();
  Model src = plan.getOrigin();
  ActionConverter ac = new ActionConverter(src);
  ob.put(ORIGIN_LABEL, mc.toJSON(src));
  JSONArray actions = new JSONArray();
  for (Action a : plan.getActions()) {
    actions.add(ac.toJSON(a));
  }
  ob.put(ACTIONS_LABEL, actions);
  return ob;
}

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

@Override
public JSONObject toJSON(Model i) throws JSONConverterException {
  JSONArray rcs = new JSONArray();
  for (ModelView v : i.getViews()) {
    rcs.add(viewsConverter.toJSON(v));
  }
  JSONObject o = new JSONObject();
  o.put(MAPPING_LABEL, toJSON(i.getMapping()));
  o.put(ATTRS_LABEL, AttributesConverter.toJSON(i.getAttributes()));
  o.put(VIEWS_LABEL, rcs);
  return o;
}

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

@Override
public JSONObject toJSON(Model i) throws JSONConverterException {
  JSONArray rcs = new JSONArray();
  for (ModelView v : i.getViews()) {
    rcs.add(viewsConverter.toJSON(v));
  }
  JSONObject o = new JSONObject();
  o.put(MAPPING_LABEL, toJSON(i.getMapping()));
  o.put(ATTRS_LABEL, AttributesConverter.toJSON(i.getAttributes()));
  o.put(VIEWS_LABEL, rcs);
  return o;
}

相关文章