欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【java】通过HttpServletRequest转换获得json对象

程序员文章站 2024-02-04 20:13:40
...

前言

转载自:http://www.mamicode.com/info-detail-2517079.html

代码

String param= null; 
try {
    BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
    StringBuilder responseStrBuilder = new StringBuilder();
    String inputStr;
    while ((inputStr = streamReader.readLine()) != null)
        responseStrBuilder.append(inputStr);
    
    JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
    param= jsonObject.toJSONString();
    System.out.println(param);
} catch (Exception e) {
    e.printStackTrace();
}
相关标签: java