javascript - json_encode unicode转义序列无法在javascript中显示

标签 javascript php json cordova unicode

json_encode(数组($myarray1,$myarray2))

在 php 上包含 unicode 转义序列,例如

[{
"Panelbuilder 32":
    [{
        "topic_id":"34",
        "forum_id":"6",
        "topic_title": "Panelbuilder 32",
        "topic_poster":"1",
        "topic_time":"1189740810",
        "topic_last_post_id":"124",
        "topic_last_poster_id":"1",
        "topic_last_poster_name":"vvv",
        "topic_last_post_time":"1189740810",
        "topic_last_post_subject":"Panelbuilder 32",
        "topic_last_view_time":"1436511928",
        "topic_replies":"0",
        "topic_replies_real":"0",
        "topic_views":"2463",
        "topic_attachment":"0",
        "topic_reported":"0",
        "topic_first_post_id":"124",
        "topic_first_poster_name":"vvv"
    }]
}, {
"124":
    [{
        "post_id":"124",
        "topic_id":"34",
        "forum_id":"6",
        "poster_id":"1",
        "poster_ip":"192.44.136.113",
        "post_time":"1189740810",
        "post_approved":"1",
        "post_reported":"0",
        "post_username":"vvv",
        "post_subject":"Panelbuilder 32",
        "post_text":"\u0e23\u0e03\u0e22\u0e04\u0e23\u0083\u0e23\u0081\u0e23\u0095\u0e22\u0e04\u0e23\u0087\u0e23\u0092\u0e23\u0081\u0e22\u0e0a\u0e23\u0093\u0e22\u0e19\u0e23\u0092\u0e22\u0e0d\u0e23\u0e03\u0e22\u0e19\u0e22\u0e01\u0e23\u0092\u0e23\u0083\u0e23\u0e03\u0e22\u0e0a\u0e23\u0e09\u0e23\u0e02\u0e22\u0e1b\u0e23\u0083\u0e23\u0e01\u0e22\u0e01\u0e23\u0083\u0e23\u0081 Panelbuilder 32 \u0e22\u0e02\u0e23\u008d\u0e22\u0e07  AB",
        "post_attachment":"0",
        "post_edit_time":"0",
        "topic_poster":"1",
        "topic_time":"1189740810",
        "topic_last_post_id":"124",
        "topic_last_poster_id":"1",
        "topic_last_poster_name":"vvv",
        "topic_last_post_time":"1189740810",
        "topic_last_post_subject":"Panelbuilder 32",
        "topic_last_view_time":"1436511928",
        "topic_replies":"0",
        "topic_replies_real":"0",
        "topic_views":"2463",
        "topic_attachment":"0",
        "topic_reported":"0",
        "topic_first_post_id":"124",
        "topic_first_poster_name":"vvv"
    }]
}]

这些 un​​icode 序列在 JavaScript 中显示,如 /ue023 (反斜杠转换为正斜杠),并且不能显示为字符。我需要在我的 PhoneGap 应用程序上显示这些字符。有什么解决办法吗?

最佳答案

正如您解释的那样,您使用 JSON.parse 这是我的解决方案:

var str = JSON.parse(data);
str.replace(/\//g, "\\");

显然,无论您如何获取字段,您都需要更新上面的代码,例如

var new_data = str[1][124][0].post_text.replace(/\//g, "\\");

关于javascript - json_encode unicode转义序列无法在javascript中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340737/

相关文章:

php - 基本安全,PHP mySQl

python - 来自嵌套 JSON 的 pandas 数据框

php - 将解析后的json数据插入到MySQL表中

javascript - 从后面开始拆分字符串

javascript - 按类排列的元素数组 - TypeError : $. id 不是函数

javascript - 当 ngIf 在 ngfor 内失败时,Angular 显示未找到数据

php - 删除不区分大小写的mysql语句在php页面中不起作用

php - 在 PHP 中延迟加载公共(public)类数据成员

javascript - 使用 JQuery 将 JSON 数据传递到 DIV 中

javascript - 简单的落沙玩具滞后