Java从HttpServletRequest中获取body中的json格式参数

public Map<String, String> getJSON(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
    StringBuilder responseStrBuilder = new StringBuilder();
    String inputStr;
    while ((inputStr = streamReader.readLine()) != null) {
    	responseStrBuilder.append(inputStr);
    }
    Map<String, String> params = JSON.parseObject(responseStrBuilder.toString(), Map.class);
    
    return params;
}

你可能感兴趣的:(Java开发中遇到的问题)