失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 怎么用json转list的集合对象 – PHP基础 – 前端 php实现日程提醒

怎么用json转list的集合对象 – PHP基础 – 前端 php实现日程提醒

时间:2020-12-29 06:02:48

相关推荐

怎么用json转list的集合对象 – PHP基础 – 前端 php实现日程提醒

简单的手动放置 键值对 到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实现日程提醒》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。