gpt4 book ai didi

java - 如何将两个 map 添加到列表中

转载 作者:行者123 更新时间:2023-12-02 10:21:29 28 4
gpt4 key购买 nike

代码是:如何将 map 添加到列表中

   public List<Map<Object, Object>> getReportees(String idOfEmp) throws Exception {

JSONArray jsonarr_s = (JSONArray) jobj.get("list");
Map<Object, Object> map = new HashMap<Object, Object>();
if (jsonarr_s.size() > 0) {

// Get data for List array
for (int i = 0; i < jsonarr_s.size(); i++) {

JSONObject jsonobj_1 = (JSONObject) jsonarr_s.get(i);
JSONObject jive = (JSONObject) jsonobj_1.get("jive");

Object names = jsonobj_1.get("displayName");
Object userid = jive.get("username");
map.put(names, userid); //return the map with the key value pairs
map = new HashMap<Object, Object>();
String UserId = userid.toString();
String output1 = resp1.getEntity(String.class);
JSONObject jobjs = (JSONObject) new JSONParser().parse(output1);

// Store the JSON object in JSON array as objects (For level 1 array element i.e
// issues)
JSONArray jsonarr_new = (JSONArray) jobjs.get("issues");
int numofjiras = jsonarr_new.size(); //this jira count must be mapped to the name and id
map.put("count", numofjiras);
}

return map;
} else {
map.put("errorcheck", msg);
}
return map;
}
}
I want the output like:

Name id count
AJ 235457 2
Geet 637571 0

实际上我正在键值对中获取名称和ID。然后我尝试将每个ID传递给一个API,它将给我计数。那么我如何返回所有字段,即名称,ID和计数。所以在这里,我试图像这个用户 ID 和名称一样进行映射,这就是计数。我们如何才能实现它。请帮忙。先谢谢了。

最佳答案

我认为您可以尝试创建一个新类来表示输出中的每一行。例如,您可以创建一个 Employee 类,如下所示:

public class Employee {
private long id;
private String name;
private int issueCount;

//getters and setters
}

然后,您可以使用此类并将 JSONArray 数组中的值分配给它。一旦获得“count”的值,您就可以将 Employee 对象添加到 map (或列表)中。

希望这有帮助。

关于java - 如何将两个 map 添加到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54322121/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com