【发布时间】:2016-08-23 07:55:17
【问题描述】:
我的目标是使用List 的Integers 过滤JSONArray 作为参数:
JSONObject record1 = new JSONObject();
record1.put("id", "44");
record1.put("name", "somename");
我当前创建新的JSONArray 并以 id 作为参数的函数:
private JSONArray modifyJsonArray(JSONArray array, final Integer param) throws JSONException {
List<JSONObject> jsons = new ArrayList<JSONObject>();
mainJsons = new ArrayList<JSONObject>();
for (int i = 0; i < array.length(); i++) {
Integer id = Integer.parseInt(array.getJSONObject(i).getString("id"));
mainJsons.add(array.getJSONObject(i));
if (id == param) {
jsons.add(array.getJSONObject(i));
}
}
return new JSONArray(jsons);
}
我想传递 List<Integer> 而不是 final Integer param。
【问题讨论】:
-
好的,有什么问题?