0
: Ich binAntwort auf Restzustand || Arraylist Liste
Meine api gibt Antwort auf restresponse als:
{"response":"{}{}{}{}","status":"OK","statusMsg":"Successful"}
Meine js nicht diese Antwort lesen konnte.
Ich möchte Antwort wie folgt:
{"response":["{},{},{},{}"],"status":"OK","statusMsg":"Successful"}
Unten ist mein Code-Schnipsel:
public static Response buildRestResponse(List object, HashMap<Long,HashMap<String,String>> newCol, String headerName, String headerValue) throws JSONException
{
RestResponse resp = new RestResponse();
resp.setStatus(Response.Status.OK);
ArrayList rows = new ArrayList<>();
List<Map<String, Object>> rows1 = new ArrayList<>();
// loop through the obect reveived as parameter
for (int i=0;i<object.size();i++){
classA res = (classA) object.get(i);
try{
//loop through the new columns
Iterator it = newCol.entrySet().iterator();
//JSONObject row = new JSONObject()
Map<String, Object> row = new HashMap<>();
row.put("id", res.getId());row.put("name", res.getName());row.put("status",res.getStatus());
while (it.hasNext()){
Map.Entry pair = (Map.Entry) it.next();
if ((Long)pair.getKey() == res.getId()){
HashMap<String,String> value =
(HashMap<String,String>)pair.getValue();
Iterator iter = value.entrySet().iterator();
while(iter.hasNext()){
Map.Entry values = (Map.Entry) iter.next();
String proValue = (String)values.getKey();
row.put(proValue, (String)values.getValue());
}
}
}
rows1.add(row);
}
catch(Exception e){
e.printStackTrace();
}
}
rows.add(rows1);
resp.setResponse(rows);
resp.setStatusMsg("Successful");
Response.ResponseBuilder responseBuilder = Response.status((Response.Status)Response.Status.OK).entity((Object)resp);
responseBuilder.header(headerName, (Object)headerValue);
return responseBuilder.build();
}
Wenn in meinem Javascript versuche ich results.response gibt nichts