临窗旋墨的博客       临窗旋墨的导航

利用jackson转成json字符串(ssh中)

 1 public String getJsonString(Object o){
 2     ObjectMapper om = new ObjectMapper();
 3    StringWriter sw = new StringWriter();
 4    try{
 5       JsonGenerator jg = new JsonFactory().createJsonGenerator(ws);
 6       om.writeValue(jg,o);
 7       jg.close();
 8    }catch(){}
 9    return ws.toString() ;
10 }
11 
12 public void writeJson(Object o) {
13   String json = getJsonString(o);
14   try{
15       ServletActionContext.getResponse().getWriter().write(json);
16    }catch(){}
17 }

 

posted @ 2014-09-24 09:57  临窗旋墨  阅读(320)  评论(0编辑  收藏  举报