
pom依赖
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
后端代码
public synchronized void manualDis(String json) {
if(json==null||"".equals(json))
return;
try {
//解码
json= java.net.URLDecoder.decode(json,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//字符串转换对象
T t = JSON.parseObject(json,T.class);
System.out.println(t);
}
前端对url进行encode编码
$.ajax({
url:'[[@{/a/b}]]',
dataType:'json',
type:'post',
data:{
json:encodeURIComponent('{list:[{id:1,roomId:1,bed:1},{id:2,roomId:2,bed:2},{id:1,roomId:1,bed:1}]}')
},
success:function(res){
console.log(res);
},
error:function(){
}
})