[英]How to print unicode json using Javascript
I try to print JSON response in my html document so I do: 我尝试在html文档中打印JSON响应,所以我这样做:
respdiv.innerHTML = '<pre><code>' + xhr.responseText + '</code></pre>';
The problem is my response is printed like this : 问题是我的答复是这样打印的:
{ "error": "Sc\\u00e9nario invalide" }
I want my response to be printed like this : 我希望我的回复像这样打印:
{ "error": "Scénario invalide" }
How I get this? 我怎么得到的?
You can delegate all the work to JSON.parse()
then unescape
the characters: 您可以将所有工作委托给JSON.parse()
然后unescape
字符:
var responseText = unescape(JSON.parse('"' + xhr.responseText + '"'));
respdiv.innerHTML = '<pre><code>' + responseText + '</code></pre>';
But as @pswg suggested, I would advice fixing it on server side. 但是正如@pswg所建议的那样,我建议在服务器端进行修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.