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(); }
    奋斗奋斗奋斗奋斗奋斗奋斗奋斗奋斗生命在于奋斗,也为自己带盐奋斗奋斗奋斗奋斗奋斗奋斗奋斗奋斗
  • 相关阅读:
    安卓系统的文件管理神器Solid Explorer(v2.2)
    地月距离竟然如此遥远
    Android在争议中逃离Linux内核的GPL约束【转】
    gearman
    PHP基础学习
    函数式编程
    有向图的实现
    无向图的实现
    百度地图API获取数据
    python队列的实现
  • 原文地址:https://www.cnblogs.com/hardwork/p/4078136.html
Copyright © 2011-2022 走看看