其他分享
首页 > 其他分享> > 以流的方式读取url中的参数

以流的方式读取url中的参数

作者:互联网

@RequestMapping(value = "/userPreference",produces="application/json;charset=utf-8")
@ResponseBody
public String userPreference(HttpServletRequest request) {
InputStreamReader reader = null;
String json = "";
try {
request.setCharacterEncoding("UTF-8");
reader = new InputStreamReader(request.getInputStream(), "UTF-8");
char[] buff = new char[1024];
int length = 0;
while ((length = reader.read(buff)) != -1) {
String x = new String(buff, 0, length);
System.out.println(x);
json = json + x;
}
}
catch (IOException e) {
e.printStackTrace();
}


JSONObject js = JSONObject.parseObject(json);
System.out.println(js);
String uid = js.getString("uid");

}



标签:读取,url,以流,js,json,reader,new,buff,String
来源: https://www.cnblogs.com/foreverstudy/p/10442645.html