JSON中的字符在Angular HTTP GET中被改变

Characters in JSON altered in Angular HTTP GET

本文关键字:GET 改变 HTTP 字符 JSON Angular      更新时间:2023-09-26

我试图从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编码