2 回答

TA貢獻1829條經驗 獲得超7個贊
我認為您可以嘗試創建一個新類來表示輸出中的每一行。例如,您可以Employee像這樣創建一個類:
public class Employee {
private long id;
private String name;
private int issueCount;
//getters and setters
}
然后,您可以使用此類并將 JSONArray 數組中的值分配給它。一旦獲得“count”的值,您就可以將 Employee 對象添加到地圖(或列表)中。
希望這可以幫助。

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]。
添加回答
舉報