从UTF8 JSON到ISO-8859-1的字符编码 [英] Character encoding from UTF8 JSON to ISO-8859-1

查看:585
本文介绍了从UTF8 JSON到ISO-8859-1的字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 getJSON 可以检索服务器端的utf8编码的一些数据...

Using getJSON to retrieve some data which I am utf8 encoding on the server-side end...

"title":"new movie \u0091The Tree of Life\u0092 on day 6"

显示的页面是charset ISO-8859-1 ,我正在这样做...

The page that is is displayed on is charset ISO-8859-1 and I am doing this...

$.getJSON('index.php', { q: q }, function(data){
    for (var i = 0; i < data.length; i++) {
        alert(data[i].title + "\n" + utf8_decode(data[i].title));
    }
});

utf8_decode 函数来自此处

问题是我还在看到两个版本的魔术方块...

The problem is that I am still seeing the magic squares for both versions...

新电影第6天的生命之树

new movie The Tree of Life on day 6

电影ᔨ生命之树⠯第6天

new movie ᔨe Tree of Life⠯n day 6

这让我相信这个字符可能不是编码。但是,如果我把字符串粘贴到一个页面,并将字符集设置为UTF8或ISO-8859-1: - /

This leads me to believe that perhaps the character is of neither encoding. However it works if I paste the string onto a page and set the charset to either UTF8 or ISO-8859-1 :-/

任何帮助将是伟大的! p>

Any help would be great!

推荐答案

在JSON中传输的数据中不需要转义或解码任何字符。它是自动完成的。它也独立于页面的编码。即使ISO-8859-1不包含欧元符号,您也可以轻松地使用代码传输和显示欧元符号( \\\€ )。

There is no need to escape or decode any characters in data transmitted in JSON. It's done automatically. It is also independent of the page's encoding. You can easily transmit and display the euro sign (\u20ac) with your code even though ISO-8859-1 does not contain the euro sign.

你的问题是字符 \\\‘ \\\’ 。它们不是有效的Unicode字符。

You problem are the characters \u0091 and \u0092. They aren't valid Unicode characters. They are for private use only.

它看起来好像你实际上有数据最初使用Windows-1250字符集,但未正确翻译为Unicode / JSON 。在Windows-1250中,这两个字符是印刷单引号。

It rather looks as if you in fact have data that originally used the Windows-1250 character set but was not properly translated to Unicode/JSON. In Windows-1250, these two characters are typographic single quotes.

这篇关于从UTF8 JSON到ISO-8859-1的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆