// 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和汉字的互相转码,解压后excel文档直接转换,方便快捷。
unicode和中文互相转换工具,支持不同编码格式。
unicode 汉字转换器 unicode 汉字转换器 基于java编写,是个jar包,安装jdk后,直接双击
unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换unicode汉字转换
该工具支持汉字和unicode之间的相互转换器
Unicode和中文的相互转换——VS2019的C++控制台项目(x64\x86\Debug\Release已编译) 1. bool ChineseToUnicode(CString cstr, string & str); 望断秋高和待雪初平__ChineseToUnicode:\u671b\u65ad\u79cb\u9ad8\u...
excel 公式 自动转换unicode编码为汉字
汉字unicode转换器,方便汉字和UNICODE之间转换!
可以将unicode编码转换成可以看懂的中文,unicode-cn.zip
从Delphi7开始,窗体文件dfm里的汉字都变成了#28162#31992之类的形式,看起来非常不直观。 而且在delphi2009,delphi2010里,...因此,做了一个转换器,可以将Unicode数字表示的汉字#28162#31992转换为正确显示的汉字。
从Delphi7开始,窗体文件dfm里的汉字都变成了#...因此,做了一个转换器,可以将Unicode数字表示的汉字#28162#31992转换为正确显示的汉字。 1.1版的改进,可以反向转换,即将含汉字的文件转换为#28382#33288之类的格式。
中文转化为unicode格式的方法类,经过程序验证完全可使用。
unicode至汉字的批量转换。unicode码1中输入待转换起始码,unicode码2中输入待转换结束码,结果在unicode.mdb中查看。
使用javascript转换汉字,很方便,可以自己修改一下源码.
自己写的一个Unicode和汉字的相互转换工具,附有源码和可执行jar包,在JDK7开下用Eclipse开发的~
Java中文成Unicode码及从Unicode码转成中文
汉字Unicode转换器,汉字Unicode可以相互转换
一个html页面 用js 实现 unicode中文互相转换工具。方便快捷
汉字与unicode转换工具
个人编写的C#版16进制unicode字符和汉字想换转换的工具,涵盖源码,可以直接运行