List> to org.json.JSONObject?

后端 未结 8 2065
借酒劲吻你
借酒劲吻你 2020-12-14 20:12
List> list = new ArrayList>();
Map map = new HashMap();

         


        
8条回答
  •  太阳男子
    2020-12-14 20:39

    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();
    }
    

提交回复
热议问题