java处理postman中的raw json(application/json) 请求方式

@PostMapping(value = “/test”)
public JSONObject Test(InputStream inputStream) {
JSONObject json=new JSONObject();
String result = “”;
try {
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];

	        int len;
	        while ((len = inputStream.read(buffer)) != -1) {
	            outSteam.write(buffer, 0, len);
	        }
	 
	        outSteam.close();
	        inputStream.close();
	        result = new String(outSteam.toByteArray(), "UTF-8");

// System.out.println(result);
result = org.apache.commons.lang3.StringEscapeUtils.unescapeJava(result);//去转义符 斜杠
String newStr = result.substring(1, result.length()-1);//去除头和尾引号
System.out.printf(newStr);
JSONObject jsonObject=JSONObject.fromObject(newStr);
System.out.println(“jsonObject:”+jsonObject);
System.out.println(jsonObject);
} catch (Exception e) {
e.printStackTrace();
}
json.put(“result”, result);
return json;
}

java处理postman中的raw json(application/json) 请求方式_第1张图片
亲测有效

你可能感兴趣的:(java)