Jmeter提取复杂json字符串
2021-02-19 19:17
标签:sonar log for 技术 inf png code mamicode res 设置: 设置: Jmeter提取复杂json字符串 标签:sonar log for 技术 inf png code mamicode res 原文地址:https://www.cnblogs.com/deeptester-vv/p/12927229.html 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 ) {
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);
上一篇:maven导出jar包的方式
下一篇:jQuery其二