This worked for me:
List jsonCategories = new ArrayList();
JSONObject jsonCategory = null;
for (ICategory category : categories) {
jsonCategory = new JSONObject();
jsonCategory.put("categoryID", category.getCategoryID());
jsonCategory.put("desc", category.getDesc());
jsonCategories.add(jsonCategory);
}
try {
PrintWriter out = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
_log.info(jsonCategories.toString());
out.write(jsonCategories.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}