编程语言
首页 > 编程语言> > Java获取POST请求Json格式参数(raw)

Java获取POST请求Json格式参数(raw)

作者:互联网

 

在这里插入图片描述

 

有两种方式:

1、已流的方式接收请求参数

// request为HttpServletRequest对象
BufferedReader br = null;
try {
    br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
} catch (IOException e) {
    e.printStackTrace();
}
String line = null;
StringBuilder sb = new StringBuilder();
try {
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    br.close();
} catch (IOException e) {
    e.printStackTrace();
}

 

2、@RequestBody注解 接收

 

@RequestMapping(value = "/technicalReviewInfo", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
@ResponseBody
public JSONObject synTechnicalReviewInfo(@RequestBody JSONObject technicalReviewJson) {
    JSONObject json=new JSONObject();
    return json;
}

 

      转自:https://blog.csdn.net/weixin_42096792/article/details/121661148

标签:Java,JSONObject,json,raw,Json,br,new,line,null
来源: https://www.cnblogs.com/todarcy/p/16399677.html