Jmeter-BeanShell断言:将数据库结果封装成list作为参数

Posted rechin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jmeter-BeanShell断言:将数据库结果封装成list作为参数相关的知识,希望对你有一定的参考价值。

 

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;

//获取数据库数据
Object dataCount = vars.getObject("result");
String dataCount_str = dataCount.toString();
JSONArray list = JSON.parseArray(dataCount_str.replace("=",":"));
JSONArray detailList = new JSONArray();
for (int i = 0; i < list.size(); i++) {

    JSONObject object = list.getJSONObject(i);
    // 添加键值对
    object.put("entryNum",12);
    object.put("entrySmallNum",object.getInteger("small_large_package_ratio")-1);
    object.put("smallLargePackageRatio",object.getInteger("small_large_package_ratio"));
    object.put("medicationId",object.getInteger("medication_id"));
    //去掉多余的键值对
    object.remove("chest_id");
    object.remove("chest_nature");
    object.remove("small_large_package_ratio");
    object.remove("medication_id");
    detailList.add(object);
}
log.info(detailList.toString());

vars.put("detailList",detailList.toString());

 

以上是关于Jmeter-BeanShell断言:将数据库结果封装成list作为参数的主要内容,如果未能解决你的问题,请参考以下文章

jmeter-beanshell断言

Jmeter-BeanShell PostProcessor提取请求及响应结果并保存到本地文件

jmeter-beanshell本地文件写入多列数据--for循环

Jmeter-BeanShell Sampler调用java代码

jmeter-beanshell参数调取

jmeter-BeanShell PreProcessor的使用