本文整理汇总了Java中com.google.gson.JsonArray.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.addAll方法的具体用法?Java JsonArray.addAll怎么用?Java JsonArray.addAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonArray
的用法示例。
在下文中一共展示了JsonArray.addAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clone
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private JsonObject clone(JsonObject source) {
JsonObject dest = new JsonObject();
for (Map.Entry<String, JsonElement> entry: source.entrySet()) {
JsonArray values = entry.getValue().getAsJsonArray();
JsonArray cloned = new JsonArray();
cloned.addAll(values);
dest.add(entry.getKey(), cloned);
}
return dest;
}
示例2: fetchArray
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonArray fetchArray(InputJsonKeys.VendorAPISource.MainTypes entityType,
int page) throws IOException {
HashMap<String, String> params = null;
if (entityType.equals(InputJsonKeys.VendorAPISource.MainTypes.topics) || entityType.equals(InputJsonKeys.VendorAPISource.MainTypes.speakers)) {
params = new HashMap<String, String>();
// Topics and speakers require param "includeinfo=true" to bring extra data
params.put("includeinfo", "true");
if (entityType.equals(InputJsonKeys.VendorAPISource.MainTypes.topics)) {
if (extractUnpublished) {
params.put("minpublishstatus", "0");
}
}
}
if (page == 0) {
page = 1;
} else if (page > 1) {
if (params == null) {
params = new HashMap<String, String>();
}
params.put("page", Integer.toString(page));
}
JsonElement element = getFetcher().fetch(entityType, params);
if (element.isJsonArray()) {
return element.getAsJsonArray();
} else if (element.isJsonObject()) {
// check if there are extra pages requiring further fetching
JsonObject obj = element.getAsJsonObject();
checkPagingConsistency(entityType, page, obj);
int pageSize = obj.get("pagesize").getAsInt();
int totalEntities = obj.get("total").getAsInt();
JsonArray elements = getEntities(obj);
if (page*pageSize < totalEntities) {
// fetch the next page
elements.addAll(fetchArray(entityType, page+1));
}
return elements;
} else {
throw new JsonParseException("Invalid response from Vendor API. Request should return "
+ "either a JsonArray or a JsonObject, but returned "+element.getClass().getName()
+". Entity fetcher is "+getFetcher());
}
}