解码前:
{“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);
// }
//}