c# json 汉字乱码_解决Json传输中文乱码问题
1、如果是通过URL传递:----需要编码两次
var searchText = this.searchText();
searchText = encodeURI(searchText);
searchText = encodeURI(searchText);
$.ajax({
type: 'GET',
url: $ctx + this.pageUrl + pageIndex + "&searchText=" + searchText,
data: '',
contentType: 'text/json,charset=utf-8',
dataType: 'json',
success: function(data) {
}
})
},
后台通过:
String queryCon = request.getParameter("searchText");
if(queryCon != null && queryCon != ""){
queryCon=URLDecoder.decode(queryCon,"utf-8");
}
反编译一下就可以获取到传递的中文~~
2、 直接通过ajax数据传递:只需编译一次~
var searchText = this.searchText();
searchText = encodeURI(searchText);
$.ajax({
type: 'GET',
url: $ctx + this.pageUrl + pageIndex ,
data: {search:searchText },
contentType: 'text/json,charset=utf-8',
dataType: 'json',
success: function(data) {
}
})
},
后台直接获取到传递的值,需要解码一次:
String queryCon = search;
if(queryCon != null && queryCon != ""){
queryCon=URLDecoder.decode(queryCon,"utf-8");
}
更多推荐
所有评论(0)