Jmeter-BeanShell断言:将数据库结果封装成list作为参数
阅读原文时间:2023年07月14日阅读:4

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");
JSONArray list = JSON.toJSON(dataCount);
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());

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章