javascript - Angular HTTP GET 中更改的 JSON 中的字符

标签 javascript json angularjs http utf-8

我正在尝试从一个 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/

相关文章:

json - 在 JSON 中禁用超文本应用程序语言 (HAL)?

javascript - angularjs ng-焦点多个字段

javascript - 云函数 - BigQuery 仅返回具有域的对象 ( null )

javascript - lodash/underscore.js 函数创建由 n 个 x 副本组成的数组

javascript - 冲突的组件 Joomla

angularjs - $httpBackend.whenGET 多参数

javascript - RestAngular:put 和 customPUT 正在发送旧对象,而不是更新对象

JavaScript 汉堡按钮不起作用

php - 如何让 JSON 与 PHP 一起使用

python - 如何在 python 中使用 Objectpath 导航包含数组的 JSON 文件以选择值?