// unicode转为本地 public static String ascii2Native(String str) { StringBuilder sb = new StringBuilder(); int begin = 0; int index = str.indexOf("\\u"); while (index != -1) { sb.append(str.substring(begin, index)); sb.append(ascii2Char(str.substring(index, index + 6))); begin = index + 6; index = str.indexOf("\\u", begin); } sb.append(str.substring(begin)); return sb.toString(); } private static char ascii2Char(String str) { if (str.length() != 6) { throw new IllegalArgumentException( "Ascii string of a native character must be 6 character."); } if (!"\\u".equals(str.substring(0, 2))) { throw new IllegalArgumentException( "Ascii string of a native character must start with \"\\u\"."); } String tmp = str.substring(2, 4); int code = Integer.parseInt(tmp, 16) << 8; tmp = str.substring(4, 6); code += Integer.parseInt(tmp, 16); return (char) code; }
例如:
{"WeatherForecast":[{"Date":"2013-06-18","City":{"Name":"\u6c49\u4e2d","ID":"610700"},"Weather":{"Desc":"\u591a\u4e91","Symbol":"03"},"Temperature":{"Low":"24","High":"33"},"Wind":{"Power":"","Direction":"\u5fae\u98ce","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"\u77ed\u8896\u886b\u3001\u77ed\u88d9\u3001\u77ed\u88e4\u3001\u8584\u578bT\u6064\u886b\u3001\u655e\u9886\u77ed\u8896\u68c9\u886b"},"Pollute":{"Index":"3","Desc":"\u5bf9\u7a7a\u6c14\u6c61\u67d3\u7269\u6269\u6563\u65e0\u660e\u663e\u5f71\u54cd"},"Cold":{"Index":"3","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u8981\u9884\u9632\u70ed\u4f24\u98ce\u8f83\u6613\u5f15\u8d77\u611f\u5192"},"Traffic":{"Index":"1","Desc":"\u80fd\u89c1\u5ea6\u5f88\u597d\uff0c\u8def\u9762\u89c6\u91ce\u5f00\u9614\uff0c\u975e\u5e38\u9002\u5b9c\u9a7e\u9a76\u6c7d\u8f66\u51fa\u884c\u3002"},"Sport":{"Index":"5","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u4e0d\u9002\u5b9c\u6237\u5916\u8fd0\u52a8"},"Tour":{"Index":"5","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u4e0d\u9002\u5b9c\u65c5\u6e38"}},{"Date":"2013-06-19","City":{"Name":"\u6c49\u4e2d","ID":"610700"},"Weather":{"Desc":"\u591a\u4e91","Symbol":"03"},"Temperature":{"Low":"26","High":"33"},"Wind":{"Power":"","Direction":"\u5fae\u98ce","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"\u77ed\u8896\u886b\u3001\u77ed\u88d9\u3001\u77ed\u88e4\u3001\u8584\u578bT\u6064\u886b\u3001\u655e\u9886\u77ed\u8896\u68c9\u886b"},"Pollute":{"Index":"3","Desc":"\u5bf9\u7a7a\u6c14\u6c61\u67d3\u7269\u6269\u6563\u65e0\u660e\u663e\u5f71\u54cd"},"Cold":{"Index":"3","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u8981\u9884\u9632\u70ed\u4f24\u98ce\u8f83\u6613\u5f15\u8d77\u611f\u5192"},"Traffic":{"Index":"1","Desc":"\u80fd\u89c1\u5ea6\u5f88\u597d\uff0c\u8def\u9762\u89c6\u91ce\u5f00\u9614\uff0c\u975e\u5e38\u9002\u5b9c\u9a7e\u9a76\u6c7d\u8f66\u51fa\u884c\u3002"},"Sport":{"Index":"5","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u4e0d\u9002\u5b9c\u6237\u5916\u8fd0\u52a8"},"Tour":{"Index":"5","Desc":"\u5929\u6c14\u95f7\u70ed\uff0c\u4e0d\u9002\u5b9c\u65c5\u6e38"}},{"Date":"2013-06-20","City":{"Name":"\u6c49\u4e2d","ID":"610700"},"Weather":{"Desc":"\u591a\u4e91\u8f6c\u9635\u96e8","Symbol":"0309"},"Temperature":{"Low":"25","High":"31"},"Wind":{"Power":"","Direction":"\u5fae\u98ce","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"\u77ed\u8896\u886b\u3001\u77ed\u88d9\u3001\u77ed\u88e4\u3001\u8584\u578bT\u6064\u886b\u3001\u655e\u9886\u77ed\u8896\u68c9\u886b"},"Pollute":{"Index":"3","Desc":"\u5bf9\u7a7a\u6c14\u6c61\u67d3\u7269\u6269\u6563\u65e0\u660e\u663e\u5f71\u54cd"},"Cold":{"Index":"2","Desc":"\u73af\u5883\u6e29\u5ea6\u8f83\u9ad8\uff0c\u867d\u7136\u4e0d\u6613\u53d1\u751f\u611f\u5192\uff0c\u8981\u63d0\u9884\u9632\u7a7a\u8c03\u75c5"},"Traffic":{"Index":"4","Desc":"\u6709\u5c0f\u96e8\uff0c\u4e0d\u592a\u9002\u5b9c\u9a7e\u9a76\u6c7d\u8f66\u51fa\u884c\uff0c\u9002\u5f53\u63a7\u5236\u8f66\u901f\u3002"},"Sport":{"Index":"5","Desc":"\u5929\u6c14\u708e\u70ed\uff0c\u4e0d\u9002\u5b9c\u6237\u5916\u8fd0\u52a8"},"Tour":{"Index":"3","Desc":"\u5929\u6c14\u708e\u70ed\uff0c\u6bd4\u8f83\u9002\u5b9c\u65c5\u6e38\u4f46\u8981\u5e26\u65f1\u4f1e\u6216\u906e\u9633\u5e3d"}}]}
转换以后
{"WeatherForecast":[{"Date":"2013-06-18","City":{"Name":"汉中","ID":"610700"},"Weather":{"Desc":"多云","Symbol":"03"},"Temperature":{"Low":"24","High":"33"},"Wind":{"Power":"","Direction":"微风","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"短袖衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫"},"Pollute":{"Index":"3","Desc":"对空气污染物扩散无明显影响"},"Cold":{"Index":"3","Desc":"天气闷热,要预防热伤风较易引起感冒"},"Traffic":{"Index":"1","Desc":"能见度很好,路面视野开阔,非常适宜驾驶汽车出行。"},"Sport":{"Index":"5","Desc":"天气闷热,不适宜户外运动"},"Tour":{"Index":"5","Desc":"天气闷热,不适宜旅游"}},{"Date":"2013-06-19","City":{"Name":"汉中","ID":"610700"},"Weather":{"Desc":"多云","Symbol":"03"},"Temperature":{"Low":"26","High":"33"},"Wind":{"Power":"","Direction":"微风","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"短袖衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫"},"Pollute":{"Index":"3","Desc":"对空气污染物扩散无明显影响"},"Cold":{"Index":"3","Desc":"天气闷热,要预防热伤风较易引起感冒"},"Traffic":{"Index":"1","Desc":"能见度很好,路面视野开阔,非常适宜驾驶汽车出行。"},"Sport":{"Index":"5","Desc":"天气闷热,不适宜户外运动"},"Tour":{"Index":"5","Desc":"天气闷热,不适宜旅游"}},{"Date":"2013-06-20","City":{"Name":"汉中","ID":"610700"},"Weather":{"Desc":"多云转阵雨","Symbol":"0309"},"Temperature":{"Low":"25","High":"31"},"Wind":{"Power":"","Direction":"微风","PowerTurn":"","DirectionTurn":""},"Cloth":{"Index":"1","Desc":"短袖衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫"},"Pollute":{"Index":"3","Desc":"对空气污染物扩散无明显影响"},"Cold":{"Index":"2","Desc":"环境温度较高,虽然不易发生感冒,要提预防空调病"},"Traffic":{"Index":"4","Desc":"有小雨,不太适宜驾驶汽车出行,适当控制车速。"},"Sport":{"Index":"5","Desc":"天气炎热,不适宜户外运动"},"Tour":{"Index":"3","Desc":"天气炎热,比较适宜旅游但要带旱伞或遮阳帽"}}]}
------------------------------------------------------------------------
public void testUDecode() { String str = "make in \u4e2d\u56fd"; for(char ch : "make in 中国".toCharArray()) { if(ch > 128) { System.out.print("\\u"+Integer.toHexString(ch)); } else { System.out.print(ch); } } System.out.println(); System.out.println(str); str = "make in \\u4e2d\\u56fd"; String v = "'"+str+"'"; System.out.println(v); try { System.out.println(new JSONTokener(v).nextValue().toString()); } catch (JSONException e) { e.printStackTrace(); } }
相关推荐
了解Unicode和汉字转换的概念以及如何利用工具进行操作,对于在跨平台和跨系统环境中处理中文数据的IT专业人士来说,是非常基础且实用的技能。通过熟练掌握这一知识点,可以避免许多因编码不匹配而引发的问题,提高...
Unicode和汉字转换是计算机处理中文字符时经常遇到的问题。Unicode是一种国际编码标准,它为世界上几乎所有的文字系统提供了一个统一的编码方式,包括汉字。汉字转换则是将汉字在不同的编码格式间进行转换,如从...
总之,汉字Unicode相互转换器是一个便捷的工具,它简化了汉字与Unicode编码之间的转换过程,对于处理汉字和Unicode相关的任务具有很高的实用价值。通过了解Unicode的基本概念和转换器的工作方式,用户可以更有效地...
unicode和中文互相转换工具,支持不同编码格式。
unicode 汉字转换器 unicode 汉字转换器 基于java编写,是个jar包,安装jdk后,直接双击
unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换
在Delphi 2009及之后的版本中,由于引入了Unicode支持,处理字符串时经常需要进行Unicode和汉字之间的转换。这篇文档将详细介绍如何在Delphi 2009中进行这种转换,并提供源码示例。 首先,了解Unicode的基础知识是...
本文将深入探讨如何将中文字符转换为 Unicode 格式,并介绍一个名为 `unicodeConvert.java` 的 Java 类,该类已通过实际程序验证,确保了其功能的可行性。 Unicode 编码通常采用 UTF-8、UTF-16 或 UTF-32 这样的...
从Delphi7开始,窗体文件dfm里的汉字都变成了#28162#31992之类的形式,看起来非常不直观。 而且在delphi2009,delphi2010里,...因此,做了一个转换器,可以将Unicode数字表示的汉字#28162#31992转换为正确显示的汉字。
总的来说,Unicode和GBK编码是现代计算机处理中文字符的关键技术,而编码转换表和相应的工具则提供了在不同编码之间进行有效转换的手段,对于进行跨平台、跨语言的软件开发至关重要。理解这些概念并熟练掌握其应用,...
Unicode和中文的相互转换——VS2019的C++控制台项目(x64\x86\Debug\Release已编译) 1. bool ChineseToUnicode(CString cstr, string & str); 望断秋高和待雪初平__ChineseToUnicode:\u671b\u65ad\u79cb\u9ad8\u...
在这个例子中,它可能链接到了一个与Unicode编码、中文转换或者与"Unicode.exe"相关的网站,提供更多的信息、教程或者更新。 Unicode编码在IT行业中有着广泛的应用。例如,HTML和XML文档使用Unicode作为其字符集的...
本文将深入探讨如何在Java中进行中文字符到Unicode编码的转换,以及如何从Unicode编码还原为中文字符。 首先,我们来了解Unicode的基本概念。Unicode是一个国际标准,它为每个字符分配了一个唯一的数字,这个数字被...
在提供的描述中,提到了一个工具或者程序,用户可以输入Unicode码的起始码和结束码,程序会将这一范围内所有的Unicode码转换为对应的汉字,并将结果存储在"unicode.mdb"文件中。".mdb"通常是Microsoft Access数据库...
汉字Unicode转换器是一种工具,主要用于在汉字和Unicode编码之间进行转换。Unicode是一种国际标准,它为世界上几乎所有的字符,包括汉字,提供了唯一的数字表示。这个转换器使得用户能够轻松地处理汉字与计算机内部...
汉字是中文字符的主要...总之,理解和掌握汉字与 Unicode 的转换技巧,是处理中文信息和跨语言通信的基础。通过合理运用编程语言中的相关函数和方法,可以方便地在两者之间进行转换,从而确保信息的准确传递和处理。
excel 公式 自动转换unicode编码为汉字
因此,做了一个转换器,可以将Unicode数字表示的汉字#28162#31992转换为正确显示的汉字。 也可以反向转换,即将含汉字的文件转换为#28382#33288之类的格式。 因客户的习惯要求,需要对工程做简繁体转换。 本工具可以...
在编程领域,尤其是在涉及到字符编码的时候,理解和操作16进制Unicode字符与汉字之间的转换是一项基本技能。在C#环境中,这项任务可以通过内置的类库和方法来实现。本工具正是针对这一需求,提供了一个方便的C#实现...
汉字Unicode转换器是一种工具,主要用于在汉字和Unicode编码之间进行转换。Unicode是一种国际标准,旨在为世界上所有语言提供一个统一的字符集,确保每个字符都有一个唯一的数字代码,便于计算机处理和显示各种语言...