java后台得到request payload请求中的json请求参数

private String getRequestPayload(HttpServletRequest req) {
StringBuilder sb = new StringBuilder();
try(BufferedReader reader = req.getReader();) {
char[]buff = new char[1024];
int len;
while((len = reader.read(buff)) != -1) {
sb.append(buff,0, len);
}
}catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}

调用该方法得到json字符串,解析json字符串即可获取所需参数。

posted @ 2019-03-25 09:42  Distracting  阅读(13130)  评论(1编辑  收藏  举报