hyy9512

导航

servlet中常用到的工具

1. 解析ajax传来的json字符串,得到json对象

 1 private JSONObject getJsonObject(HttpServletRequest req) {
 2         StringBuffer json=new StringBuffer();
 3         String lineString=null;
 4         BufferedReader reader;
 5         JSONObject data=null;
 6         try {
 7             reader = req.getReader();
 8             while((lineString=reader.readLine())!=null) {
 9                 json.append(lineString);
10             }
11              data=JSONObject.fromObject(json.toString());
12         } catch (IOException e) {
13             e.printStackTrace();
14         }
15         return data;
16     }

 

posted on 2017-12-17 15:09  hyy9512  阅读(154)  评论(0编辑  收藏  举报