简单的手动放置 键值对 到JSONObject,然后在put到JSONArray对象里List<Article> al = articleMng.find(f); System.out.println(al.size()); HttpServletResponse hsr = ServletActionContext.getResponse(); if(null == al){return ; } for(Article a : al){System.out.println(a.getId()+a.getDescription()+a.getTitle()); } JSONArray json = new JSONArray()
; for(Article a : al){JSONObject jo = new JSONObject()
;jo.put("id", a.getId());jo.put("title", a.getTitle())
;jo.put("desc", a.getDescription());json.put(jo); } try {System.out.println(json.toString())
;hsr.setCharacterEncoding("UTF-8")
;hsr.getWriter().write(json.toString()); } catch (IOException e) {e.printStackTrace(); }复制代码上述代码JSONArray是引入的org.json.JSONArray包
如果觉得《怎么用json转list的集合对象 – PHP基础 – 前端 php实现日程提醒》对你有帮助,请点赞、收藏,并留下你的观点哦!