本文主要是介绍将文本中的unicode字符替换成汉字,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景介绍
msql workbench导出数据库表的数据
导出的json数据
[{"english_id":1, "english_word":"ambition", "homophonic":"am-\u4ffa\uff0cbi-\u5fc5,tion-\u80dc\uff1a\u4ffa\u5fc5\u80dc", "chinese":"\u91ce\u5fc3"},{"english_id":2, "english_word":"touche", "homophonic":"tou-\u900f,che-\u5f7b:\u900f\u5f7b", "chinese":"\u8bb2\u5f97\u597d\uff0c\u4e00\u9635\u89c1\u8840\u5730"},{"english_id":3, "english_word":"comprehension", "homophonic":"com-\u770b,pre-\u7834,hen-\u7ea2,sion-\u5c18\uff1a\u770b\u7834\u7ea2\u5c18\uff0c\u5c31\u9886\u609f\u4e86\u4e86\u4eba\u751f\u7684\u771f\u8c1b", "chinese":"\u9886\u609f\u529b"},{"english_id":4, "english_word":"administration", "homophonic":"ad\u4ffa\u7684,mini-\u547d\u4ee4,stration-\u6b7b\u9075\u5faa:\u4ffa\u7684\u547d\u4ee4\u6b7b\u9075\u5faa", "chinese":"\u884c\u653f\u7ba1\u7406"},{"english_id":5, "english_word":"mendacity", "homophonic":"men-\u7537\u4eba,da-\u5927,city:\u57ce\u5e02:\u7537\u4eba\u5230\u4e86\u5927\u57ce\u5e02\uff0c\u5c31\u6492\u8c0e", "chinese":"\u865a\u4f2a"}]
中的汉字变成了unicode字符
解决办法
使用js打印到控制台,在浏览器中看就是汉字了。
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><script>var str = `[{"english_id":1, "english_word":"ambition", "homophonic":"am-\u4ffa\uff0cbi-\u5fc5,tion-\u80dc\uff1a\u4ffa\u5fc5\u80dc", "chinese":"\u91ce\u5fc3"},{"english_id":2, "english_word":"touche", "homophonic":"tou-\u900f,che-\u5f7b:\u900f\u5f7b", "chinese":"\u8bb2\u5f97\u597d\uff0c\u4e00\u9635\u89c1\u8840\u5730"},{"english_id":3, "english_word":"comprehension", "homophonic":"com-\u770b,pre-\u7834,hen-\u7ea2,sion-\u5c18\uff1a\u770b\u7834\u7ea2\u5c18\uff0c\u5c31\u9886\u609f\u4e86\u4e86\u4eba\u751f\u7684\u771f\u8c1b", "chinese":"\u9886\u609f\u529b"},{"english_id":4, "english_word":"administration", "homophonic":"ad\u4ffa\u7684,mini-\u547d\u4ee4,stration-\u6b7b\u9075\u5faa:\u4ffa\u7684\u547d\u4ee4\u6b7b\u9075\u5faa", "chinese":"\u884c\u653f\u7ba1\u7406"},{"english_id":5, "english_word":"mendacity", "homophonic":"men-\u7537\u4eba,da-\u5927,city:\u57ce\u5e02:\u7537\u4eba\u5230\u4e86\u5927\u57ce\u5e02\uff0c\u5c31\u6492\u8c0e", "chinese":"\u865a\u4f2a"}]`;console.log(str);</script>
</body></html>
这篇关于将文本中的unicode字符替换成汉字的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!