如何使用 angular js 或 Javascript 解码为 UTF-8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30501454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:17:16  来源:igfitidea点击:

How to decode into UTF-8 using angular js or Javascript

javascriptjsonangularjsutf-8

提问by Yasser B.

I started recently to use angular js, I like how it works, I want to know how can I set the charset encoding as a header.

我最近开始使用angular js,我喜欢它的工作方式,我想知道如何将字符集编码设置为标题。

My json file contains special characters ( French language ).

我的 json 文件包含特殊字符(法语)。

something like : Rempla?§ant

就像是 : Rempla?§ant

Is there any way to decode that into UTF-8 after retreiving it :

有什么方法可以在检索后将其解码为 UTF-8:

here is my code :

这是我的代码:

$http.get("http://int.footballclub.orange.com/live/lineup/fr_lineup_253959.json"
})
        .success(function (response) {
            $scope.lineup = response;    

        });

回答by Tom Blodget

As you initially said, you can add a request header. That way you don't have to translate it if the server supports UTF-8.

正如您最初所说,您可以添加请求标头。这样,如果服务器支持 UTF-8,您就不必翻译它。

An exampleby Banasci:

一个例子Banasci

$http.get('resources/negozi.json',
    {headers : {'Content-Type' : 'application/json; charset=UTF-8'}
}).success(function(data) {
... code here
});

Also, see the documentation.

另外,请参阅文档