BeanShell PostProcessor提取json数据

1.10.2获取我的日记血压数据列表接口hcGetDiartPresureList 

需求:提取sample返回json数据中所有diaryId字段值,jmeter中添加后置处理器BeanShell PostProcessor: 

import org.json. • 
tring 
response_data 
JSONObject data_obj 
trine diayList str 
Script: 
prev. getRes pon seDataAsString 
o; 
— new 
= . .toString(); 
10 
'tog. 
JSONArray diayList_array = new JSONArray(diaryList str) ; 
trinsC) result = new 
StringCdiayList_array. length ( ) ; 
//tog. ist_array. ist_array. Length()); 
Il afor(int 
JSONObject diayList_obj = new .toString()); 
String recordltems_str = .toString 
o; 
JSONArray recordltems array = new ; 
StringC) results 
StringCrecordItems_array. length ( ) ) ; 
//tog. info ( "recordltems_array. Length= "+recordltems_array. Length ) ; 
for(int length() ;j++) 
JSONObject diayld_obj = new .toString()); 
String diayld_str = .toString(); 
results 
= diayld_str; 
vars . , 
Arrays . toString(resuIts) ) ; 
25

 

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));  

} 

 

posted @ 2017-11-28 12:41  春田花花同学会  阅读(2108)  评论(1编辑  收藏  举报