我正在尝试使用以下命令将json文件(JSON数组)加载到javascript:
$.ajax({
type: "GET",
url: "data.json", //contains array of json objects
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(json) {
console.log(json[0].name);
},
error: function(xhr, textStatus, errorThrown) {
$("#error").html(xhr.responseText);
}
});
json[0].name
的值为:
//in data.json, it is like this (it is Arabic):
\u00cd\u00ed\/\u00c3\u00d4\u00c8\u00ed\u00e1\u00ed\u00e5 \u00c7\u00e1\u00e3\u00e4\u00d8\u00de\u00c9 \u00c7\u00e1\u00ce\u00c7\u00e3\u00d3\u00c9 \u00da\u00d4\u00d1
//console.log(json[0].name) gives this instead
Íí/ÃÔÈíáíå ÇáãäØÞÉ ÇáÑÇÈÚÉ ÚÔÑ
data.json
文件是由PHP脚本自动生成的,我使用utf8_encode()
编码阿拉伯字符串并将其正确存储在文件中。
我认为这是一个编码问题,但我不确定如何修复它。