Actually I am trying to parse the two api's json data in the same class. I know it should not be done but this is the requirement. I am getting data from the hashmap. And I want to add it in the table.But the problem is program adds only last item in table. but while debugging it's giving all values.
Here is my code:
public class services2
{
public Map<Object, Object> getReportees(String idOfEmp) throws Exception {
......
if(resp.getStatus() != 200){
System.err.println("Unable to connect to the server");
}
String output = resp.getEntity(String.class);
//Store the JSON objects in an array
//Get the index of the JSON object and print the values as per the index
JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject)parse.parse(output);
JSONArray jsonarr_1 = (JSONArray) jobj.get("list");
Map<Object, Object> map=new HashMap<Object,Object>();
for(int i=0;i<jsonarr_1.size();i++){
JSONObject jsonobj_1 = (JSONObject)jsonarr_1.get(i);
JSONObject jive = (JSONObject)jsonobj_1.get("jive");
String var = jive.get("username").toString();
values = var;
if(resp1.getStatus() != 200){
system.err.println("Unable to connect to the server");
}
String output1 = resp1.getEntity(String.class);
JSONObject jobjs = (JSONObject) new JSONParser().parse(output1);
JSONArray jsonarr_11 = (JSONArray) jobjs.get("issues");
System.out.println("count"+jsonarr_11.size());
Object obj3 = jsonarr_11.size();
int counter = (Integer) obj3;
System.out.println(counter);
Object obj1 = jsonobj_1.get("displayName");
Object obj2 = jive.get("username");
map.put(obj1, obj2);
map.put("obj3", obj3);
System.out.println(obj3);
}
return map; //for the map obj3 return only the last count that is 1
}
}
Here when I am trying to send the map obj3. I am getting only the last value. I actually want the count in a correct way.
This is the output:
Number id username count
1 A12345 Anagha R 1
2 M12345 Madhusudan S 1
3 AT12345 Amreen Taj 1
Expected output is:
1 A12345 Anagha R 0
2 M12345 Madhusudan S 0
3 AT12345 Amreen Taj 1
When I am trying to print in the console it is giving me the right count but when I am trying through the map it is sending only the last value that is count 1.