本文整理匯總了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());
}
}