Jmeter提取复杂json字符串
设置:
设置:
import com.alibaba.fastjson.*; //获取从上一个请求返回的数据 String rspData = prev.getResponseDataAsString(); //把从结果中得到的json数据转成json对象 JSONObject dataObj = JSONObject.parseObject(rspData); //因为 loanList 是在data中,所以还要得到data对象 JSONObject jsonData = dataObj.getJSONObject("data"); //data对象的loanList转成json 数组 JSONArray loanLists = jsonData.getJSONArray("loanList"); //通过for循环得到数组的中的对象,然后根据属性得到相应的值 JSONObject loanObject; String loanNo = null ; String loanState = null; String loanAmt= null; for (int i = 0; i < loanLists.size(); i++) { loanObject = (JSONObject) loanLists.get(i); loanState = loanObject.getString("loanState"); if (loanState.equals("RP")) { loanNo = loanObject.getString("loanNo"); loanAmt = loanObject.getString("loanAmt"); break; } } //log.info("----------------------------------------" + loanNo); vars.put("RPLoanNo",loanNo); vars.put("RPLoanAmt",loanAmt);