将后盾的数据传递到.json文件中

将后台的数据传递到.json文件中
比如
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("li", li);
然后把它传递给data.jsion,应该怎么做,求指点。。。
------解决思路----------------------
jason就是一个map,你往map里面put然后再写回去不就好了
------解决思路----------------------
把你想要传到前台的数据,使用map把数据put
------解决思路----------------------
public ModelAndView getNewsCategory(HttpServletRequest request,
HttpServletResponse response, ModelAndView mav) throws Exception {
// TODO Auto-generated method stub
ArrayList<NewsCategory> newscatlist = new ArrayList<NewsCategory>();
int type = Integer.valueOf(request.getParameter("type"));
String  typeid = request.getParameter("typeid");
newscatlist = this.newsManager.dogetNewsCategorybytype(type, typeid);
this.outJson(request, response, JSON.toJSONString(newscatlist));
return null;

}


参考上述代码,你定义好实体pojo对象,往里面填充对应的对象属性即可,然后用第三方开源json lib包把java对象或者数组转换成json字符串,丢给httpServletresponse即可

开源的json lib包可以用阿里的fastJson jar包,比较好用,支持嵌套对象