需要使用maven生产org.json.jar包放在jmeterlibext下
测试计划中引用这个jar包
beanshell:
//提取响应内容 String statusCode = prev.getResponseCode(); //获取响应代码 String response_body = prev.getResponseDataAsString(); //获取响应body内容 String response_headers = prev.getResponseHeaders(); //获取响应头 String response_reason = prev.getResponseMessage(); //获取响应信息 log.info("=====响应代码:=====>>"+statusCode); log.info("=====响应body:=====>>"+response_body); log.info("=====响应头:=====>>"+response_headers); log.info("=====响应信息:=====>>"+response_reason); import org.json.JSONObject; import org.json.JSONArray; JSONObject JsonData = new JSONObject(response_body);//json格式化 log.info("=====JsonData:=====>>"+JsonData); String strdata = JsonData.get("data").get("ocTrackingNumber").toString(); log.info("=====data:=====>>"+strdata); String filename = "C:\Users\Desktop\单号.txt"; FileWriter writer; try { writer = new FileWriter(filename,true); writer.write(strdata); writer.write(" "); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); }