@GET
@Produces("application/json")
@Consumes("application/json")
@Path("/getStuff/{id}")
public String getStuff(
@PathParam("id") String id,
@Context HttpServletRequest request,
@Context HttpServletResponse response) throws Exception
{
Collection<Stuff> stuff = Manager.getStuff().values();
JSONArray jArray = new JSONArray();
for (Stuff i : stuff)
{
jsnObjct.put("id", i.getId());
jsnObjct.put("name", i.getName());
jArray.add(jsnObjct);
}
json = jArray.toString();
response.setContentType("text/javascript");
response.getOutputStream().print(json);
response.flushBuffer();
return null;
}
for (Stuff i : stuff)Collection<Stuff>before he iterates over it. He can break apart eachStuffinto aTreeMapwhere key=getId()and val=getName(), for example, then iterate over theTreeMapand build his JSON array. He could extend theJSONObjectclass and make it comparable.