request中获取post的json对象数据content-type=“text/plain”
request中获取post的json对象数据content-type=“text/plain”public ReqReturnEntity getPostByTextPlain(HttpServletRequest request) throws IOException {ReqReturnEntity result = new ReqReturnEntity();List<CEntity
·
request中获取post的json对象数据content-type=“text/plain”
public ReqReturnEntity getPostByTextPlain(HttpServletRequest request) throws IOException {
ReqReturnEntity result = new ReqReturnEntity();
List<CEntity> cEntityList = new ArrayList<>();
try {
BufferedReader reader = request.getReader();
char[] buf = new char[512];
int len = 0;
StringBuffer contentBuffer = new StringBuffer();
while ((len = reader.read(buf)) != -1) {
contentBuffer.append(buf, 0, len);
}
logger.info(contentBuffer.toString());
String reqInfo = JSONUtil.formatJsonStr(contentBuffer.toString());//text文本转json
JSONArray jsonArray = JSONUtil.parseArray(reqInfo);//json转jsonArray
cEntityList = (List<CEntity>) jsonArray.toList(CEntity.class);//jsonArray转List集合
result = SaveSteelArrivalPlan(cEntityList);
} catch (IOException e) {
e.printStackTrace();
logger.error("[获取request中用POST方式“Content-type”是“text/plain”发送的json数据]异常:{}", e.getCause());
}
return result;
}
com.alibaba fastjson 1.2.28更多推荐
所有评论(0)