本文整理匯總了Java中com.eclipsesource.json.JsonArray.forEach方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonArray.forEach方法的具體用法?Java JsonArray.forEach怎麽用?Java JsonArray.forEach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.eclipsesource.json.JsonArray
的用法示例。
在下文中一共展示了JsonArray.forEach方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchFromAPI
import com.eclipsesource.json.JsonArray; //導入方法依賴的package包/類
private static List<SampServer> fetchFromAPI(final String apiAddress) throws MalformedURLException, IOException {
final List<SampServer> servers = new ArrayList<>();
// The pages are 1 indexed, so we start at 1 and go up to 100, lets be real, 100 is too much anyways.
for (int i = 1; i < 100; i++) {
final String json = readUrl(apiAddress + "?page=" + i);
// In case the page equals null, we have already received all data.
if (Objects.isNull(json) || json.equalsIgnoreCase("null")) {
break;
}
final JsonArray jsonArray = Json.parse(json).asArray();
jsonArray.forEach(object -> {
final JsonObject jsonServerData = object.asObject();
final String address = jsonServerData.getString("ip", UNKNOWN);
final String[] addressData = address.split(":");
final int port = address.contains(":") ? Integer.parseInt(addressData[1]) : ServerUtility.DEFAULT_SAMP_PORT;
final SampServer server = new SampServer(addressData[0], port);
server.setPlayers(jsonServerData.getInt("pc", 0));
server.setMaxPlayers(jsonServerData.getInt("pm", 0));
server.setMode(jsonServerData.getString("gm", UNKNOWN));
server.setHostname(jsonServerData.getString("hn", UNKNOWN));
server.setLanguage(jsonServerData.getString("la", UNKNOWN));
servers.add(server);
});
}
return servers;
}
示例2: jsonToSet
import com.eclipsesource.json.JsonArray; //導入方法依賴的package包/類
private Set<NodeId> jsonToSet(JsonArray nodes) {
final Set<NodeId> nodeIds = Sets.newHashSet();
nodes.forEach(node -> nodeIds.add(NodeId.nodeId(node.asString())));
return nodeIds;
}