我正在尝试从一个 Restful 服务中获取一个 JSON 对象。当我将 URL 插入我的浏览器(Firefox 或 Chrome)时,我收到了具有正确 UTF-8 编码的 JSON:
{"name":"Université"}
但是,当我尝试在我的 Angular 应用程序中获取相同的 URL 时,文本未正确编码。这是从 JavaScript 控制台打印出来的对象:
{ name: "Universit�"}
这是我在 Angular 中使用的代码:
$http(
{
method: "GET",
url: 'localhost:8080/my/url/location',
headers : {
"Accept":"application/json;charset=utf-8",
"Accept-Charset":"charset=utf-8"
}
}
).success(function(data,status,headers,config){
console.log(data);
/* the rest of the success function */
}).error(function(data,status,headers,config){
/* the rest of the failure function */
});
有什么想法吗?提前致谢!
最佳答案
问题不在于代码,而在于 JSON 的源文件没有以 UTF-8 编码
关于javascript - Angular HTTP GET 中更改的 JSON 中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31704247/