struts2编写接口,获取对方传递的json格式的数据

public String getStrResponse(){
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
InputStream inputStream;
String strResponse = "";
try {
inputStream = request.getInputStream();
String strMessage = "";
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
while ((strMessage = reader.readLine()) != null) {
strResponse += strMessage;
}
reader.close();
inputStream.close();
} catch (Exception e) {
LOG.info(e.getMessage(),e);
}
return strResponse;
}

 

JSONObject jsonRequest = JSONObject.parseObject(getStrResponse());

 
posted @ 2020-11-27 17:27  为了忘却的纪念丶  阅读(3)  评论(0)    收藏  举报