// 获取Body中的json字符串进行解析--------------------------------------------------------------
// 获取Request对象
HttpServletRequest request = ServletActionContext.getRequest();
StringBuffer sb = new StringBuffer();
try {
// json格式字符串
String jsonStr = "";
// 获取application/json格式数据,返回字符流
BufferedReader reader = request.getReader();
// 对字符流进行解析
while ((jsonStr = reader.readLine()) != null) {
sb.append(jsonStr);
}
} catch (IOException e) {
e.printStackTrace();
}
// 将json字符串(jsonStr)-->json对象(JSONObject)
JSONObject jo = JSONObject.fromObject(sb.toString()).getJSONObject("data");
System.out.println(jo);
String logis_no = jo.getString("logis_no"); //单号
String weight = jo.getString("weight"); //重量
String file = jo.getString("file"); //图片base64
解析json
解析JSON请求数据
最新推荐文章于 2023-10-30 11:37:02 发布
本文介绍了一种从HTTP请求中解析JSON格式数据的方法,通过ServletActionContext获取Request对象,读取并解析application/json格式的数据,最终将JSON字符串转换为JSON对象。
3196

被折叠的 条评论
为什么被折叠?



