Jmeter 查看结果树显示unicode转中文

Jmeter 查看结果树显示unicode转中文

 

 

 

 

 

解决方法:

还是先要将jmeter.properties的默认编码改为UTF-8

sampleresult.default.encoding=UTF-8

 

 

 

 

再通过后置处理器的beanshell的方式,将请求到的unicode数据转成中文

 

 

String response_value=new String(prev.getResponseData(),"UTF-8");
        char aChar;
        int num= response_value.length();
        StringBuffer outBuffer=new StringBuffer(num);
        for(int x =0; x <num;){
            aChar= response_value.charAt(x++);
            if(aChar=='\\'){
                aChar= response_value.charAt(x++);
                if(aChar=='u'){
                    int value =0;
                    for(int i=0;i<4;i++){
                        aChar= response_value.charAt(x++);
                        switch(aChar){
                            case'0':
                            case'1':
                            case'2':
                            case'3':
                            case'4':
                            case'5':
                            case'6':
                            case'7':
                            case'8':
                            case'9':
                                value=(value <<4)+aChar-'0';
                                break;
                            case'a':
                            case'b':
                            case'c':
                            case'd':
                            case'e':
                            case'f':
                                value=(value <<4)+10+aChar-'a';
                                break;
                            case'A':
                            case'B':
                            case'C':
                            case'D':
                            case'E':
                            case'F':
                                value=(value <<4)+10+aChar-'A';
                                break;
                            default:
                                throw new IllegalArgumentException(
                                        "Malformed   \\uxxxx  encoding.");}}
                    outBuffer.append((char) value);}else{
                    if(aChar=='t')
                        aChar='\t';
                    else if(aChar=='r')
                    aChar='\r';
                    else if(aChar=='n')
                    aChar='\n';
                    else if(aChar=='f')
                    aChar='\f';
                    outBuffer.append(aChar);}}else
                outBuffer.append(aChar);}
        prev.setResponseData(outBuffer.toString());

 

posted @ 2021-11-24 13:24  西夏一品唐  阅读(85)  评论(0编辑  收藏  举报