如1.10.2获取我的日记血压数据列表接口hcGetDiartPresureList
需求:提取sample返回json数据中所有diaryId字段值,jmeter中添加后置处理器BeanShell PostProcessor:
import org.json.*;
String response_data = prev.getResponseDataAsString();
JSONObject data_obj = new JSONObject(response_data);
String diaryList_str = data_obj.get("result").get("diaryList").toString();
//log.info(diaryList_str);
JSONArray diaryList_array = new JSONArray(diaryList_str);
String[] result = new String[diaryList_array.length()];
//log.info("diaryList_array.length()="+diaryList_array.length());
for(int i=0;i<diaryList_array.length();i++){
JSONObject diaryList_obj = new JSONObject(diaryList_array.get(i).toString());
String recordItems_str = diaryList_obj.get("recordItems").toString();
JSONArray recordItems_array = new JSONArray(recordItems_str);
String[] results = new String[recordItems_array.length()];
//log.info("recordItems_array.length="+recordItems_array.length());
for(int j=0;j<recordItems_array.length();j++)
{
JSONObject diaryId_obj = new JSONObject(recordItems_array.get(j).toString());
String diaryId_str = diaryId_obj.get("diaryId").toString();
results[j] = diaryId_str;
}
vars.put("result", Arrays.toString(results));
}