public static void main(String[] args) {
String s = "测试";
String tt = gbEncoding(s); // String tt1 = "你好,我想给你说一个事情";
System.err.println(s + " to unicode :" + tt);
System.err.println(tt + " decode unicode :" + decodeUnicode(tt));
} public static String gbEncoding(final String gbString) {
char[] utfBytes = gbString.toCharArray();
String unicodeBytes = "";
for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
String hexB = Integer.toHexString(utfBytes[byteIndex]);
if (hexB.length() <= 2) {
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "\\u" + hexB;
}
return unicodeBytes;
} public static String decodeUnicode(final String dataStr) {
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while (start > -1) {
end = dataStr.indexOf("\\u", start + 2);
String charStr = "";
if (end == -1) {
charStr = dataStr.substring(start + 2, dataStr.length());
} else {
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
start = end;
}
return buffer.toString();
}

unicode转码,如:\u6d4b\u8bd5转成中文“测试”的更多相关文章

  1. jmeter接口测试--响应结果Unicode转码成中文

    jmeter接口测试-响应结果Unicode转码成中文 一般情况下,接口返回数据都会经过加密,所以有时相应结果会显示为Unicode,因此,需添加BeanShell PostProcessor,加入代 ...

  2. Jmeter-响应结果unicode转成中文显示

    本文为转载微信公众号文章,如作者发现后不愿意,请联系我进行删除 原文链接:http://mp.weixin.qq.com/s?__biz=MjM5OTI2MTQ3OA==&mid=265217 ...

  3. php 解决json_encode中文UNICODE转码问题

    用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似"\u***"的格式,如果想汉字不进行转码,这里提供三种方法 1.升级PHP,在PHP5. ...

  4. [转]php 解决json_encode中文UNICODE转码问题

    FROM : http://blog.csdn.net/bjash/article/details/9834497 用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, ...

  5. 解决json_encode中文UNICODE转码问题

    用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式,如果想汉字不进行转码,这里提供三种方法 .升级PHP,在PHP5., 这个问题终于得以解 ...

  6. 在eclipse中安装properties插件PropertiesEditor及设置(附图),ASCII码转换成中文

    在eclipse中安装properties插件PropertiesEditor及设置(附图),ASCII码转换成中文安装成功后ASCII还是不能转换成中文的,原因是设置里面没有把编码设置为utf8的, ...

  7. Python 读取文件中unicode编码转成中文显示问题

    Python读取文件中的字符串已经是unicode编码,如:\u53eb\u6211,需要转换成中文时有两种方式 1.使用eval: eval("u"+"\'" ...

  8. jmeter响应信息unicode 编码转成中文

    在jmeter 发送请求过程中,有时候后台返回的是unicode 代码,如: {"status":-1,"msg":"\u63d0\u4ea4\u65 ...

  9. JAVA unicode转换成中文

    /** * * unicode 转换成 中文 * @param theString * @return */ public static String decodeUnicode(String the ...

随机推荐

  1. PHP的压力测试工具ab.exe 和mpm介绍提高并发数

    该工具是apache自带的,可以用它来测试网站的并发量有多大和某个页面的访问时间. 基本用法: 1.  进入CMD,转到apache的bin目录下. 2.  执行命令ab.exe  -n 访问的问次数 ...

  2. php 表单提交

    <?php header("Content-Type:text/html; charset=utf8"); class config{ public static funct ...

  3. 使用Storm实现实时大数据分析

    摘要:随着数据体积的越来越大,实时处理成为了许多机构需要面对的首要挑战.Shruthi Kumar和Siddharth Patankar在Dr.Dobb’s上结合了汽车超速监视,为我们演示了使用Sto ...

  4. SQL Server 2008 Express 安装或卸载时提示“重启计算机失败"的解决办法

    安装或卸载SQL Server 遇到错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作.运行安装程序之前必须重新启动计算机.如下图: 解决办法: 1.在开始->运行中输入regedi ...

  5. storm 随机发送字符串

    Storm的程序叫做Topology,类似MapReduce job 一个Topolog应该有Spout,代表数据源,和若干个bolt 首先写一个Spout public class RandomSp ...

  6. Rs2008内存管理策略

    Rs2008 在内存管理方面已经有了很大的改变.主要增加了文件缓存,允许把内存数据卸载到文件缓存中.而Rs2005 都是把数据放到内存中.对于大数据量的报表而言,很容易出现OutOfMemory 错误 ...

  7. ArrayList和LinkedList的几种循环遍历方式及性能对比分析(转载)

    原文地址: http://www.trinea.cn/android/arraylist-linkedlist-loop-performance/ 原文地址: http://www.trinea.cn ...

  8. UI design principles

    Master's conclusion: 1. fix a color pattern 2. fix the frames the UI will use 3. fix the subject tha ...

  9. &nbsp|&quot|&amp|&lt|&gt等html字符转义

    提示:请直接按CTRL+F搜索您要查找的转义字符.    原文地址:http://write.blog.csdn.net/postedit/8817826 常用表: No. 文字表記 10進表記 16 ...

  10. JSP和servlet有什么区别?

    JSP和servlet有什么区别? JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是"类servlet". Servlet ...