com.google.gson.JsonArray.add()方法的使用及代码示例

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

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

JsonArray.add介绍

[英]Adds the specified element to self.
[中]将指定的元素添加到self。

代码示例

代码示例来源:origin: fabric8io/docker-maven-plugin

public static JsonArray newJsonArray(List<String> list) {
  final JsonArray jsonArray = new JsonArray();
  for(String element : list)
  {
    jsonArray.add(element);
  }
  return jsonArray;
}

代码示例来源:origin: chanjarster/weixin-java-tools

@Override
public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException {
 String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers";
 JsonObject jsonObject = new JsonObject();
 jsonObject.addProperty("tagid", tagId);
 JsonArray jsonArray = new JsonArray();
 for (String userId : userIds) {
  jsonArray.add(new JsonPrimitive(userId));
 }
 jsonObject.add("userlist", jsonArray);
 post(url, jsonObject.toString());
}

代码示例来源:origin: searchbox-io/Jest

private static void addPatternListToSource(JsonObject sourceObject, String rule, List<String> patternList) {
  if (!patternList.isEmpty()) {
    JsonArray ruleArray;
    if (sourceObject.has(rule)) {
      ruleArray = sourceObject.get(rule).getAsJsonArray();
    } else {
      ruleArray = new JsonArray();
      sourceObject.add(rule, ruleArray);
    }
    for (String pattern : patternList) {
      ruleArray.add(pattern);
    }
  }
}

代码示例来源:origin: stackoverflow.com

Vertx vertx = Vertx.newVertx();
 EventBus eventBus = vertx.eventBus()
 HttpServer server = vertx.createHttpServer();
 JsonArray permitted = new JsonArray();
 permitted.add(new JsonObject());
 SockJSServer sockJSServer = new DefaultSockJSServer(vertx, server);
 sockJSServer.bridge(new JsonObject().putString("prefix", "/pusher"), permitted, permitted);
 server.listen(<some port>);

代码示例来源:origin: searchbox-io/Jest

@Override
public String getData(Gson gson) {
  String data;
  if (sortList.isEmpty() && includePatternList.isEmpty() && excludePatternList.isEmpty()) {
    data = query;
  } else {
    JsonObject queryObject = gson.fromJson(query, JsonObject.class);
    if (queryObject == null) {
      queryObject = new JsonObject();
    }
    if (!sortList.isEmpty()) {
      JsonArray sortArray = normalizeSortClause(queryObject);
      for (Sort sort : sortList) {
        sortArray.add(sort.toJsonObject());
      }
    }
    if (!includePatternList.isEmpty() || !excludePatternList.isEmpty()) {
      JsonObject sourceObject = normalizeSourceClause(queryObject);
      addPatternListToSource(sourceObject, "includes", includePatternList);
      addPatternListToSource(sourceObject, "excludes", excludePatternList);
    }
    data = gson.toJson(queryObject);
  }
  return data;
}

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

@Override
public void setProperty(final Object obj, final Object key, final Object value) {
  if (isMap(obj)) {
    toJsonObject(obj).add(key.toString(), createJsonElement(value));
  } else {
    JsonArray array = toJsonArray(obj);
    int index;
    if (key != null) {
      index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
    } else {
      index = array.size();
    }
    if (index == array.size()) {
      array.add(createJsonElement(value));
    } else {
      array.set(index, createJsonElement(value));
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

public String toJson() {
 JsonObject details = new JsonObject();
 details.addProperty(FIELD_LEVEL, level.toString());
 JsonArray conditionResults = new JsonArray();
 for (EvaluatedCondition condition : this.conditions) {
  conditionResults.add(toJson(condition));
 }
 details.add("conditions", conditionResults);
 details.addProperty(FIELD_IGNORED_CONDITIONS, ignoredConditions);
 return details.toString();
}

代码示例来源:origin: stackoverflow.com

JsonArray jArray = new JsonArray();
JsonPrimitive element = new JsonPrimitive("value1");
jArray.add(element);

代码示例来源:origin: fabric8io/docker-maven-plugin

private void addEnvironment(Properties envProps) {
  JsonArray containerEnv = new JsonArray();
  Enumeration keys = envProps.keys();
  while (keys.hasMoreElements()) {
    String key = (String) keys.nextElement();
    String value = envProps.getProperty(key);
    if (value == null) {
      value = "";
    }
    containerEnv.add(key + "=" + value);
  }
  createConfig.add("Env", containerEnv);
}

代码示例来源:origin: jamesagnew/hapi-fhir

public static JsonObject addObj(JsonArray arr) {
 JsonObject res = new JsonObject();
 arr.add(res);
 return res;
}

代码示例来源:origin: camunda/camunda-bpm-platform

private void put(JsonElement value) {
 if (pendingName != null) {
  if (!value.isJsonNull() || getSerializeNulls()) {
   JsonObject object = (JsonObject) peek();
   object.add(pendingName, value);
  }
  pendingName = null;
 } else if (stack.isEmpty()) {
  product = value;
 } else {
  JsonElement element = peek();
  if (element instanceof JsonArray) {
   ((JsonArray) element).add(value);
  } else {
   throw new IllegalStateException();
  }
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

@Override
public void userDelete(String[] userids) throws WxErrorException {
 String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
 JsonObject jsonObject = new JsonObject();
 JsonArray jsonArray = new JsonArray();
 for (int i = 0; i < userids.length; i++) {
  jsonArray.add(new JsonPrimitive(userids[i]));
 }
 jsonObject.add("useridlist", jsonArray);
 post(url, jsonObject.toString());
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData create(boolean... values) {
  JsonArray array = new JsonArray();
  for (boolean val : values) {
    array.add(new JsonPrimitive(val));
  }
  return new GsonPersistedData(array);
}

代码示例来源:origin: fabric8io/docker-maven-plugin

public ContainerHostConfig binds(List<String> bind) {
  if (bind != null && !bind.isEmpty()) {
    JsonArray binds = new JsonArray();
    for (String volume : bind) {
      volume = EnvUtil.fixupPath(volume);
      if (volume.contains(":")) {
        binds.add(volume);
      }
    }
    startConfig.add("Binds", binds);
  }
  return this;
}

代码示例来源:origin: fabric8io/docker-maven-plugin

private void addFilters(Builder builder, String... filter) {
  if (filter.length > 0) {
    if (filter.length % 2 != 0) {
      throw new IllegalArgumentException("Filters must be given as key value pairs and not " + Arrays.asList(filter));
    }
    JsonObject filters = new JsonObject();
    for (int i = 0; i < filter.length; i +=2) {
      JsonArray value = new JsonArray();
      value.add(filter[i+1]);
      filters.add(filter[i],value);
    }
    builder.p("filters",filters.toString());
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData create(float... values) {
  JsonArray array = new JsonArray();
  for (float val : values) {
    array.add(new JsonPrimitive(val));
  }
  return new GsonPersistedData(array);
}

代码示例来源:origin: jamesagnew/hapi-fhir

public PackageGenerator file(String name) {
 JsonArray files = object.getAsJsonArray("files");
 if (files == null) {
  files = new JsonArray();
  object.add("files", files);
 }
 files.add(new JsonPrimitive(name));
 return this;
}

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

@Override
  public JsonElement serialize(Filters src, Type typeOfSrc, JsonSerializationContext context) {
    final JsonObject result = new JsonObject();
    final JsonArray viewFilters = new JsonArray();
    for (DashboardFilter f : src.filters()) {
      viewFilters.add(context.serialize(f, DashboardFilter.class));
    }
    result.add(KEY_FILTERS, viewFilters);
    return result;
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData create(double... values) {
  JsonArray array = new JsonArray();
  for (double val : values) {
    array.add(new JsonPrimitive(val));
  }
  return new GsonPersistedData(array);
}

代码示例来源:origin: jamesagnew/hapi-fhir

public PackageGenerator file(String name) {
 JsonArray files = object.getAsJsonArray("files");
 if (files == null) {
  files = new JsonArray();
  object.add("files", files);
 }
 files.add(new JsonPrimitive(name));
 return this;
}

相关文章