本文整理汇总了Java中org.json.JSONArray.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.forEach方法的具体用法?Java JSONArray.forEach怎么用?Java JSONArray.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.forEach方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultValuesToOrders
import org.json.JSONArray; //导入方法依赖的package包/类
private JSONArray addDefaultValuesToOrders(JSONArray productTypeOrders) {
if(productTypeOrders == null || productTypeOrders.length() == 0)
return productTypeOrders;
productTypeOrders.forEach(orderObj -> {
JSONObject order = (JSONObject) orderObj;
if(! order.has("type"))
order.put("type", defaultOrderType.toString());
if(! order.has("margin_percent"))
order.put("margin_percent", defaultMargin);
});
return productTypeOrders;
}
示例2: fetchOrganizationList
import org.json.JSONArray; //导入方法依赖的package包/类
public List<Organization> fetchOrganizationList() throws IOException, HttpException, WebApiException {
List<Organization> result = new ArrayList<>();
Map<String, String> args = new HashMap<>();
args.put(API_ARG_KEY, key);
JSONObject answer = new JSONObject(api.sendGetRequest(API_PATH_LIST_ORGS, args));
if (ErrorUtils.isSuccessful(answer)) {
JSONArray orga = answer.getJSONArray(API_ARG_ORGANIZATIONS);
orga.forEach(o -> {
if (o instanceof JSONObject) {
JSONObject crt = (JSONObject) o;
result.add(new Organization(this, crt.getInt(API_ARG_ID), crt.getString(API_ARG_NAME), crt.getInt(API_ARG_OWNER)));
}
});
} else {
throw ErrorUtils.parseError(answer);
}
return result;
}
示例3: getMCPServiceList
import org.json.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<Peer> getMCPServiceList() {
Set<String> failstubs = new HashSet<>();
JSONArray ja = null;
loop: for (Set<String> a: new Set[]{mcpActiveAddresses, mcpPassiveAddresses}) {
for (String hostprotocolstub: a) {
try {
ServiceResponse response = APIServer.getAPI(ServicesService.NAME).serviceImpl(hostprotocolstub, new JSONObject());
ja = response.getArray();
break loop;
} catch (IOException e) {
failstubs.add(hostprotocolstub);
}
}
}
removeMCP(failstubs);
List<Peer> list = new ArrayList<>();
if (ja == null) return list;
ja.forEach(j -> list.add(new Peer((JSONObject) j)));
return list;
}
示例4: getRelicsForUser
import org.json.JSONArray; //导入方法依赖的package包/类
public static List<Relic> getRelicsForUser(long userID) {
List<Relic> relics = new ArrayList<>();
JSONObject donatorsObj = premiumObj.getJSONObject(DONATORS);
JSONArray donatorRelics = donatorsObj.optJSONArray(Long.toString(userID));
if(donatorRelics != null) {
donatorRelics.forEach(relicObj -> relics.add(new Relic((JSONObject) relicObj)));
}
return relics;
}
示例5: load
import org.json.JSONArray; //导入方法依赖的package包/类
private void load() {
try {
JSONObject mainObj = new JSONObject(NetUtils.getBody("https://opentdb.com/api_category.php"));
JSONArray categoriesArray = mainObj.getJSONArray("trivia_categories");
categoriesArray.forEach(obj -> categories.put(((JSONObject) obj).getInt("id"), ((JSONObject) obj).getString("name")));
} catch (JSONException | IOException err) {
LogUtils.errorf(err, "An error occurred while getting Trivia categories.");
}
}
示例6: BuildImmutableArray
import org.json.JSONArray; //导入方法依赖的package包/类
private List<Path> BuildImmutableArray(JSONArray DataArray){
ArrayList<Path> Builder = new ArrayList();
DataArray.forEach(file -> Builder.add(new File(file.toString()).toPath()));
return Collections.unmodifiableList(Builder);
}
示例7: offset
import org.json.JSONArray; //导入方法依赖的package包/类
public static Map<String, List<OffsetStat>> offset(String group, String topic, String start, String end) {
Map<String, List<OffsetStat>> statsMap = new HashMap<String, List<OffsetStat>>();
String indexPrefix = SystemManager.getConfig().getEsIndex();
try {
ElasticsearchAssistEntity assistEntity = ScrollSearchTemplate.getInterval(start, end);
List<String> indexes = new ArrayList<String>();
assistEntity.getIndexs().forEach(a -> {
indexes.add(indexPrefix + "-" + a);
});
String[] esHost = SystemManager.getConfig().getEsHosts().split("[,;]")[0].split(":");
String url = "http://" + esHost[0] + ":" + esHost[1] + "/" + String.join(",", indexes) + "/"
+ SystemManager.getElasticSearchOffsetType() + "/_search?ignore_unavailable=true&allow_no_indices=true";
ResponseEntity<String> response = REST.exchange(url, HttpMethod.POST,
new HttpEntity<String>(ScrollSearchTemplate.getOffset(group, topic, assistEntity), headers), String.class);
String searchResult = response.getBody();
JSONObject temp = new JSONObject(searchResult);
JSONArray temp2 = temp.getJSONObject("aggregations").getJSONObject("aggs").getJSONArray("buckets");
List<OffsetStat> stats = new ArrayList<OffsetStat>();
temp2.forEach(obj -> {
JSONObject item = (JSONObject) obj;
JSONArray xx = item.getJSONObject("group").getJSONArray("buckets");
for (int i = 0; i < xx.length(); i++) {
JSONObject item2 = xx.getJSONObject(i);
JSONArray xxx = item2.getJSONObject("topic").getJSONArray("buckets");
for (int j = 0; j < xxx.length(); j++) {
JSONObject item3 = xxx.getJSONObject(j);
stats.add(new OffsetStat(item.getLong("key"), item2.get("key").toString(), item3.get("key").toString(),
item3.getJSONObject("offset").getLong("value"), item3.getJSONObject("lag").getLong("value")));
}
}
});
stats.forEach(a -> {
String topicName = a.getTopic();
if (topicName == null || topicName.length() == 0) {
topicName = "empty";
}
if (statsMap.containsKey(topicName)) {
statsMap.get(topicName).add(a);
} else {
List<OffsetStat> arr = new ArrayList<OffsetStat>();
arr.add(a);
statsMap.put(topicName, arr);
}
});
statsMap.forEach((key, val) -> {
for (int i = val.size() - 1; i > 0; i--) {
val.get(i).setOffset(val.get(i).getOffset() - val.get(i - 1).getOffset());
}
val.remove(0);
});
} catch (Exception e) {
// TODO
LOG.error("Damn...", e);
}
return statsMap;
}