前端上传的Json数据如下所示:
{
"name":"百度跳线",//产品名字
"data":[
{"num": 1, "gongxu": "bq"}//gongxu:工序名称,名字已经统一。num:排名顺序
{"num": 2, "gongxu": "rs"}
{"num": 3, "gongxu": "slsjzp"}
//.......
//.......
]
}
在Java后台的Servlet中通过以下代码获取请求体:
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
// 1. 获取请求体中的内容
BufferedReader br = new BufferedReader(
new InputStreamReader(request.getInputStream(), "utf-8"));
StringBuffer sb = new StringBuffer("");
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
br.close();
String params = sb.toString();
System.out.println(params);
最后得出的结果却包含乱码:
name=%E6%9D%A1%E7%BA%BF&data%5B0%5D%5Bnum%5D=1&data%5B0%5D%5Bgongxu%5D=ym&data%5B1%5D%5Bnum%5D=2&data%5B1%5D%5Bgongxu%5D=yj&data%5B2%5D%5Bnum%5D=3&data%5B2%5D%5Bgongxu%5D=yinddj
这里不仅有乱码,而且data字段也有好几个,请问怎么样才能把前端传的数据原封不动的取出来呢?