在jmeter中使用BeanShell 后置处理程序遍历json的所有数据

发布于 2022年 05月 19日 01:31

在处理jmeter返回的数据时,遇到这个数据

{"data":
  [{"Hash":"404b","taskId":"123"},{"Hash":"396c","taskId":"123"},{"Hash":"f7a4","taskId":"123"},{"Hash":"f7a4","taskId":"123"},{"Hash":"f7a4","taskId":"133"},{"Hash":"f7a4","taskId":"1232"},{"Hash":"f7a4","taskId":"123"},{"Hash":"f7a4","taskId":"12321"},{"Hash":"f7a4","taskId":"123"},{"Hash":"f7a4","taskId":"123"}],
"statusCode":200}

  我使用beanshell提取的时候用了如下方法:

 

 

 

 

 

String p1 = System.getProperty("user.dir");
String p2 = System.getProperty("file.separator");
String p3 = "user_taskid.csv";
String path = p1 + p2 + p3;
String key= vars.get("taskIdlist_ALL"); //将json提取器的数值 放在key这里
 
list=Arrays.asList(key.split(","));
 

FileWriter fileWriter = new FileWriter(new File(path), true);
BufferedWriter writer = new BufferedWriter(fileWriter);
for (int i=1; i<list.size(); i++){
        String value = list.get(i);//将遍历出来的值转换成String,并传入value
        writer.append( value+"\n");
         
     
    }
 

writer.close();
fileWriter.close();

 

推荐文章