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

时间:2015-07-10 12:26:03

标签: 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"
    }]
}]

这些unicode序列以javascript显示,如/ue023(反斜杠转换为正斜杠),不能显示为字符。我需要在我的phonegap应用程序中显示这些字符。有什么解决方案吗?

1 个答案:

答案 0 :(得分:0)

正如您解释的那样使用JSON.parse继承我的解决方案:

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

但是显然你得到了你的字段,你需要更新上面的代码,例如

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