如何使用jQuery解码UTF8字符?

时间:2011-06-27 19:17:34

标签: javascript jquery utf8-decode

我刚刚解决了在这个帖子中使用utf8_decode函数输出外来字符的问题:How do I convert, display and store this characters in PHP?

它通过直接回显结果来工作但现在我有这个json_encode函数传递给jquery的结果。 Json_encode将我的数据转移到这样的东西:

{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"}

我如何从jquery json_decode? 谢谢你的任何建议。

3 个答案:

答案 0 :(得分:5)

jQuery直接从parseJSON对象提供jQuery方法:

var data = $.parseJSON('{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"}');

但是,如果通过AJAX获取数据,$.getJSON将在内部运行,并将$.parseJSON的结果作为请求的最终结果传递。

答案 1 :(得分:2)

要么直接写入JS,在这种情况下什么也不做,或者你在jQuery中使用ajax方法之一,在这种情况下只需指定dataType"json"

答案 2 :(得分:1)

var obj = JSON.parse('{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"}');
相关问题