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 应用程序上显示这些字符。有什么解决办法吗?
最佳答案
正如您解释的那样,您使用 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/