这是我的代码:
<?php
$a = array('chào','thân','ái','và','quyết','thắng');
?>
<script>
var abc = '<?php echo json_encode($a); ?>';
</script>
运行时,我得到abc变量是:
var abc = '["ch\u00e0o","th\u00e2n","\u00e1i","v\u00e0","quy\u1ebft","th\u1eafng"]';
那么,如何转换它像以前一样?我希望它成为
var abc = '["chào","thân","ái","và","quyết","thắng"]';
答案 0 :(得分:1)
这里可能有你的回答: How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?
但为什么要翻译那些应该通过php(json_decode)和javascript(JSON.parse)正确显示和正确翻译的转义序列?
答案 1 :(得分:0)
如果你的php是&gt; = 5.4,你可以使用JSON_UNESCAPED_UNICODE
标志按原样编码unicode字符:
var abc = '<?php echo json_encode($a, JSON_UNESCAPED_UNICODE); ?>';
但是,转义后的表单工作得很好并且不易出错,因此我建议您继续使用它。