為什麼我的中文出現亂碼,怎麼設置啊?
前台代碼:
$(document).ready(function(){
$('a').click(function(){
$.ajax({
type: "GET",
url: "page"+$(this).text()+".json",
headers: {
//contentType : "application/json",
// "Content-Encoding": "UTF-8"
},
dataType: "json",
success: function (data) {
$('#ul').html('');
for(i=0;i
var pageResult = "商品編號:"+data[i].GoodId+"商品名稱:"+data[i].GoodName+"商品價格:"+data[i].GoodPrice;
$("").html(pageResult).appendTo($('#ul'));
}
}
});
}
);
});
後台代碼只是一個json文件
[
{
"GoodId": "100",
"GoodName": "堅果手機",
"GoodPrice": "1999"
},
{
"GoodId": "101",
"GoodName": "IPhone",
"GoodPrice": "5000"
},
{
"GoodId": "102",
"GoodName": "華為",
"GoodPrice": "1000"
}
]
記事本打開json文件,另存為,將編碼選擇為utf-8,存儲替換原來的文件就行了
或者將中文轉為16進制編碼,這樣100%不會亂碼
[
{
"GoodId": "100",
"GoodName": "\u575a\u679c\u624b\u673a",
"GoodPrice": "1999"
},
{
"GoodId": "101",
"GoodName": "IPhone",
"GoodPrice": "5000"
},
{
"GoodId": "102",
"GoodName": "\u534e\u4e3a",
"GoodPrice": "1000"
}
]
javascript/asp.net轉換字符串為16進制編碼