zoukankan      html  css  js  c++  java
  • Ajax调用返回json数组,对象 (JSONArray.fromObject)

       JSONArray和JSONObject的详细使用:http://blog.csdn.net/yangbobo1992/article/details/8350765
      /** * ajax调用返回json数组 * @param list */ public void printList(List<?> list){ HttpServletResponse response = ServletActionContext.getResponse(); //获取response实例 response.setContentType("text/html");      //设置输出类型 response.setCharacterEncoding("UTF-8"); //设置输出编码 /*JsonConfigFactory.getInstance(); JSONArray jsonArray = new JSONArray(); jsonArray.addAll(list, JsonConfigFactory.getInstance()); */ try { response.getWriter().print(JSONArray.fromObject(list, JsonConfigFactory.getInstance())); } catch (IOException e) { e.printStackTrace(); } } /** * ajax调用返回json对象 * @param obj */ public void printObject(Object obj){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try { response.getWriter().print(JSONObject.fromObject(obj,JsonConfigFactory.getInstance())); } catch (IOException e) { e.printStackTrace(); } } /** * ajax调用返回json对象 * @param obj */ public void printSting(String str){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try { response.getWriter().print(str); } catch (IOException e) { e.printStackTrace(); }
    奋斗奋斗奋斗奋斗奋斗奋斗奋斗奋斗生命在于奋斗,也为自己带盐奋斗奋斗奋斗奋斗奋斗奋斗奋斗奋斗
  • 相关阅读:
    SystemManage_系统管理
    安装openoffice.org
    Skill_技巧
    squid代理服务器架设与维护
    FreeBSD 添加硬盘并分区操作说明
    常见游戏端口
    /usr was not properly dismounted 解决办法
    自动获取电信/网通等IP列表
    Cacti文档下载(linux/windows Cacti安装、cacti模板、cacti插件)
    实现基于DNS的负载均衡
  • 原文地址:https://www.cnblogs.com/hardwork/p/4078136.html
Copyright © 2011-2022 走看看