标签:jackson bean eval except XML mave maven roc str
在使用Jmeter接口测试过程当中,我们需要经常查看JSON的返回值,不是中文显示而且还未格式化,不易读。1.首先下载jackson-annotations、jackson-core、jackson-databind 版本均为2.8.6,下载地址如下:
https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.8.6/jackson-annotations-2.8.6.jar
https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.8.6/jackson-core-2.8.6.jar
https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.8.6/jackson-databind-2.8.6.jar
将下载后的文件统一放入到Jmeter安装目录下lib\ext目录下,我的jmeter目录是D:\apache-jmeter-5.3\lib\ext
PS:为啥放到这个文件夹下呢,因为启动jmeter的时候会自动加载进来就不需要手动加载了
2.修改jmeter.properties文件,这个文件在D:\apache-jmeter-5.3\bin\jmeter.properties
将
#sampleresult.default.encoding=ISO-8859-1
修改为
sampleresult.default.encoding=utf-8
或者直接在文件的末尾添加这行
PS:这个步骤不做的话你会发现返回的还是会有????这样的字符
3.在线程组中,新增一个后置处理器的beanshell后置处理程序
内容为
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
try {
String response_data = prev.getResponseDataAsString();
log.info("response_data: " + response_data);
ObjectMapper objectMapper = new ObjectMapper();
Map readValue = objectMapper.readValue(response_data, Map.class);
String writeValueAsString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(readValue);
log.info("PrettyFromatJson result: " + writeValueAsString);
prev.setResponseData(writeValueAsString);
} catch (JsonProcessingException e) {
log.info("BeanShell PostProcessor failed=======================================", ex);
}
通过如上处理之后JSON就很容易通过肉眼读出来了
标签:jackson bean eval except XML mave maven roc str
原文地址:https://blog.51cto.com/fengwan/2549509