亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將兩個地圖添加到列表中

如何將兩個地圖添加到列表中

慕工程0101907 2022-05-20 18:24:39
代碼是:如何將地圖添加到列表中   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 和名稱進行映射,這是計數。我們如何才能實現它。請幫助。謝謝。
查看完整描述

2 回答

?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

我認為您可以嘗試創建一個新類來表示輸出中的每一行。例如,您可以Employee像這樣創建一個類:


public class Employee {

    private long id;

    private String name;

    private int issueCount;


    //getters and setters

}

然后,您可以使用此類并將 JSONArray 數組中的值分配給它。一旦獲得“count”的值,您就可以將 Employee 對象添加到地圖(或列表)中。


希望這可以幫助。


查看完整回答
反對 回復 2022-05-20
?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

您需要先聲明一個本地列表,然后返回該列表:


    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>();

        List<Map<Object, Object>> resultList = new ArrayList<Map<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


                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);


            }

            resultList.add(map);

        } else {

            map.put("errorcheck", msg);

            resultList.add(map);

        }

        return resultList;

    }

根據您的結果,盡管您應該考慮將數據對象翻轉為


    Map<Object, List<Object>>

其中地圖中的第一個對象是它們的名稱,然后列表將包含兩個對象[id,count]。


查看完整回答
反對 回復 2022-05-20
  • 2 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號