Jmeter提取复杂json字符串
Posted 美女爱找茬
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jmeter提取复杂json字符串相关的知识,希望对你有一定的参考价值。
设置:
设置:
1 import com.alibaba.fastjson.*; 2 3 //获取从上一个请求返回的数据 4 String rspData = prev.getResponseDataAsString(); 5 //把从结果中得到的json数据转成json对象 6 JSONObject dataObj = JSONObject.parseObject(rspData); 7 8 //因为 loanList 是在data中,所以还要得到data对象 9 JSONObject jsonData = dataObj.getJSONObject("data"); 10 11 //data对象的loanList转成json 数组 12 JSONArray loanLists = jsonData.getJSONArray("loanList"); 13 14 //通过for循环得到数组的中的对象,然后根据属性得到相应的值 15 JSONObject loanObject; 16 String loanNo = null ; 17 String loanState = null; 18 String loanAmt= null; 19 for (int i = 0; i < loanLists.size(); i++) { 20 loanObject = (JSONObject) loanLists.get(i); 21 loanState = loanObject.getString("loanState"); 22 if (loanState.equals("RP")) { 23 loanNo = loanObject.getString("loanNo"); 24 loanAmt = loanObject.getString("loanAmt"); 25 break; 26 } 27 } 28 //log.info("----------------------------------------" + loanNo); 29 vars.put("RPLoanNo",loanNo); 30 vars.put("RPLoanAmt",loanAmt);
以上是关于Jmeter提取复杂json字符串的主要内容,如果未能解决你的问题,请参考以下文章