//读取ajax post参数
public static Map<String, String> bufferdReader(HttpServletRequest request) throws IOException, JSONException{
String lsBuf = "";
BufferedReader loReader = request.getReader();
String lsLine;
while ((lsLine = loReader.readLine()) != null) {
lsBuf += lsLine + "\n";
}
Map<String, String> map = parseSingle(lsBuf);
return map;
}
// 解析单个元素
public static Map<String, String> parseSingle(String psJson) throws JSONException {
JSONObject loJson = new JSONObject(psJson);
Iterator<String> loIterator = loJson.keys();
Map<String, String> lmResult = new HashMap<String, String>();
while (loIterator.hasNext()) {
String lsKey = loIterator.next();
lmResult.put(lsKey, loJson.getString(lsKey));
}
return lmResult;
}java 读取页面中ajax post 传来的参数
最新推荐文章于 2023-09-25 16:09:00 发布
本文介绍了一种从AJAX POST请求中读取并解析JSON参数的方法。通过使用BufferedReader和JSONObject,可以将请求体中的JSON字符串转换为Map对象,便于进一步的数据处理。
1635

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



