jmeter 获取json 数组指定数据输出,并设置为变量

//导入json包
import org.json.*;
//获取获取请求的返回值
//String response_data = prev.getResponseDataAsString(); 
String ="{\"errcode\":0,\"errmsg\":\"成功!\",\"data\":[{\"index\":0,\"mock_verify\":false,\"enable_script\":false,\"_id\":7234,\"uid\":53,\"add_time\":1568804712,\"up_time\":1568804712,\"project_id\":17,\"col_id\":129,\"interface_id\":9956,\"casename\":\"case1\",\"req_params\":[],\"req_headers\":[{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be49974\",\"name\":\"userId\",\"value\":\"\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be49973\",\"name\":\"userToken\",\"value\":\"\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be49972\",\"name\":\"SDKCEId\",\"value\":\"7a9582bd-8660-4f1a-9d0f-8451f688c67b\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be49971\",\"name\":\"userInfo\",\"value\":\"\"}],\"req_query\":[{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be49970\",\"name\":\"sign\",\"desc\":\"\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be4996f\",\"name\":\"timestamp\",\"desc\":\"\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be4996e\",\"name\":\"salt\",\"desc\":\"\"},{\"required\":\"1\",\"_id\":\"5d820f68b8bc8a636be4996d\",\"name\":\"appVersion\",\"desc\":\"\"}],\"req_body_form\":[],\"__v\":0,\"path\":\"/playurl/v1/play/playurl?contId=640121647&rateType=1&chip=9956\",\"method\":\"GET\",\"title\":\"case2\",\"res_body_type\":\"json\"},{\"index\":0,\"mock_verify\":false,\"enable_script\":true,\"_id\":7079,\"uid\":53,\"add_time\":1568798214,\"up_time\":1568798889,\"project_id\":17,\"col_id\":129,\"interface_id\":9770,\"casename\":\"case2\",\"req_params\":[],\"req_headers\":[{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e9\",\"name\":\"userId\",\"value\":\"\"},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e8\",\"name\":\"userToken\",\"value\":\"\"},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e7\",\"name\":\"SDKCEId\",\"value\":\"7a9582bd-8660-4f1a-9d0f-8451f688c67b\"},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e6\",\"name\":\"userInfo\",\"value\":\"\"}],\"req_query\":[{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e5\",\"name\":\"sign\",\"desc\":\"\",\"enable\":true},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e4\",\"name\":\"timestamp\",\"desc\":\"\",\"enable\":true},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e3\",\"name\":\"salt\",\"desc\":\"\",\"enable\":true},{\"required\":\"1\",\"_id\":\"5d81f606b8bc8a636be496e2\",\"name\":\"appVersion\",\"desc\":\"\",\"enable\":true}]}]}";
String title = "case2"; 
//日志打印获取请求的返回值
JSONObject data_obj = new JSONObject(response_data);

JSONArray data_str = data_obj.getJSONArray("data");
log.info(data_str.toString());

int len = data_str.length(); 

String strlen = Integer.toString(len);

vars.put("MessageNum",strlen);

log.info(strlen);


for(int i =0;i

 

你可能感兴趣的:(jmeter,学习笔记)