将 JSON 解析为 UTF-8

Joh*_*hew 1 javascript php jquery json utf-8

我正在使用以下代码从页面获取 JSON 并将其解析为我的 HTML 页面。JSON 未以 UTF-8 显示,因此具有奇怪的字符。如何删除奇怪的字符?

$.get("test.php", function (data) {
    var JSON = jQuery.parseJSON(data);
    $.each(JSON.deals.items, function (index, value) {
        // My code
    });
});
Run Code Online (Sandbox Code Playgroud)

Lau*_*art 6

请确保您流程的每一步都是 UTF-8:

  • 数据库连接
  • 数据库表
  • 您的 PHP 文件
  • 您输出的内容类型标头

    header('Content-Type: application/json; charset=utf-8');

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

参考:PHP json_encode json_decode UTF-8

编辑:如果您\u00a3的 JSON 提要中已经有奇怪的字符而不是£符号,那么您的问题已经得到解答:https : //stackoverflow.com/questions/1423846/convert-unicode-from-json-string-with-php