将jmeter接口返回值中unicode码解码为中文

解码前:
{“has_more”: false, “results”: [{“last_modifier”: 0, “repo_id”: “b5fea50b-a8dd-4d0f-b303-f1ba95442e34”, “mtime”: 1565315389, “mode”: 16384, “obj_name”: “\u5f20\u5f66\u5f66”, “path”: “/\u6d4b\u8bd5\u6587\u4ef6”, “obj_id”: “0000000000000000000000000000000000000000”, “size”: 0}]}

解码后:
{“has_more”: false, “results”: [{“last_modifier”: 0, “repo_id”: “b5fea50b-a8dd-4d0f-b303-f1ba95442e34”, “mtime”: 1565315389, “mode”: 16384, “obj_name”: “测试”, “path”: “/测试文件”, “obj_id”: “0000000000000000000000000000000000000000”, “size”: 0}]}

1)jmeter接口后面添加beanshell后置处理器:
2)将下面代码写入js脚本区域内
//获取搜索接口返回结果
String str=new String(prev.getResponseData(),“UTF-8”);

//import java.util.regex.Matcher;
//import java.util.regex.Pattern;

//public class a {

//解码

// public static String decode(str) {
char[] chars = str.toCharArray();
StringBuilder buffer = new StringBuilder();
for (int i = 0, len = chars.length; i < len;) {
char c = chars[i++];
switch © {
case 0:
case ‘\n’:
case ‘\r’:
break;
case ‘\’:
c = chars[i++];
switch © {
case ‘b’:
buffer.append(’\b’);
break;
case ‘t’:
buffer.append(’\t’);
break;
case ‘n’:
buffer.append(’\n’);
break;
case ‘f’:
buffer.append(’\f’);
break;
case ‘r’:
buffer.append(’\r’);
break;
case ‘u’:
buffer.append((char) Integer.parseInt(new String(new char[] {//
chars[i++], chars[i++], chars[i++], chars[i++] //
}), 16));//
break;
case ‘x’:
buffer.append((char) Integer.parseInt(new String(new char[] {//
chars[i++], chars[i++] //
}), 16));//
break;
default:
buffer.append©;
}
break;
default:
buffer.append©;
}
}
prev.setResponseData(buffer.toString());
// }

// public static void main(String[] args) {
// String unicode = decode(str);
// System.out.println(unicode);
// }
//}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值