
正文
jmeter-在beanshell里用代码提取参数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
接口返回json(response_data):
{
"Code":1,
"Message":null,
"Error":null,
"Data":{
"Tire":["20寸及以上轮毂安装及动平衡",
"朝阳轮胎安装服务【14-15寸】",
], "Beautify":[
{
"Cost":"14.00",
"Price":"14.00",
"DefaultPrice":"14.00",
"OriginalPrice":"15.00",
"DayLimit":98,
"ActivityId":null,
"ActivityName":null,
"StartTime":null,
"SalesStrategyType":"Default",
"CategoryId":160,
"RootCategoryName":"挪车贴",
"RootCategoryId":159,
"Description":"用户",
"ProductName":"挪车车贴贴",
"PID":"FU-MD-NCT-F|1",
"PKID":760,
"CategoryName":"挪车贴",
"EndTime":null,
"SoldCount":48,
"TodaySurplus":98,
"ProductCommentRate":4,
"BigImageUrl":null,
"SmallImageUrl":null
},
{
"Cost":"9.90",
"Price":"9.90",
"DefaultPrice":"20.00",
"OriginalPrice":"100.00",
"DayLimit":1,
"ActivityId":"71383419-8811-4f5b-9522-33865214c62e",
"ActivityName":"9.9洗车",
"StartTime":"2019/06/04 12:22:09",
"SalesStrategyType":"Groupon",
"CategoryId":4,
"RootCategoryName":"美容清洗",
"RootCategoryId":1,
"Description":"整车泡沫冲洗擦干",
"ProductName":"标准洗车-五座轿车",
"PID":"FU-MD-BZXC-F|1",
"PKID":482,
"CategoryName":"标准洗车",
"EndTime":"2020/01/06 16:45:00",
"SoldCount":334,
"TodaySurplus":1,
"ProductCommentRate":4,
"BigImageUrl":null,
"SmallImageUrl":null
},
{
"Cost":"20.00",
"Price":"20.00",
"DefaultPrice":"20.00",
"OriginalPrice":"100.00",
"DayLimit":96,
"ActivityId":null,
"ActivityName":null,
"StartTime":null,
"SalesStrategyType":"Default",
"CategoryId":4,
"RootCategoryName":"美容清洗",
"RootCategoryId":1,
"Description":"整车",
"ProductName":"标准洗车-五座轿车",
"PID":"FU-MD-BZXC-F|1",
"PKID":482,
"CategoryName":"标准洗车",
"EndTime":null,
"SoldCount":334,
"TodaySurplus":96,
"ProductCommentRate":4,
"BigImageUrl":null,
"SmallImageUrl":null
},
{
"Cost":"11.00",
"Price":"11.00",
"DefaultPrice":"11.00",
"OriginalPrice":"50.00",
"DayLimit":10,
"ActivityId":null,
"ActivityName":null,
"StartTime":null,
"SalesStrategyType":"Default",
"CategoryId":7,
"RootCategoryName":"全车打蜡",
"RootCategoryId":2,
"Description":"标准洗车、全车打蜡",
"ProductName":"测试001",
"PID":"FU-MD-QCDL-F|37",
"PKID":114,
"CategoryName":"全车打蜡",
"EndTime":null,
"SoldCount":82,
"TodaySurplus":10,
"ProductCommentRate":5,
"BigImageUrl":null,
"SmallImageUrl":null
},
],
"ShopDetail":{"Images":[ "https://img3.tuhu.org/Images/Marketing/Shops/f9c9/8ecc/182e30783031398cf89bee7d_w192_h192.png@600w_600h_100Q.png"
],
"ShopCertification":640,
"HeaderImage":"https://img4.tuhu.org/Images/Marketing/Shops/681be77a-a591-4425-bfec-3cf57181d51e.jpg@600w_600h_100Q.jpg",
"ShopImages":[
"https://img3.tuhu.org//Shop/ShopIntroPics/5c09/8974/8bcb8551fed1869b61abcdc5_w536_h300.jpg",
"https://img3.tuhu.org//Shop/ShopIntroPics/d386/e4a4/c031b88a62f5ffefa0e8f28e_w192_h168.jpg"
]
]
}
}
提取Data下的Beautify,判断如果名字为标准洗车,则提取价格
代码如下:
【】是array
{}是object
导入jar包
import org.json.JSONArray;
import org.json.JSONObject;
JSONObject jsonObject = new JSONObject(response_data);
JSONObject result = jsonObject.getJSONObject("Data");
JSONArray beautify = result.getJSONArray("Beautify");
for (int i = 0 ; i<beautify.length() ; i++){
JSONObject info = beautify.getJSONObject(i);
String categoryName = info.getString("CategoryName");
String price = info.getString("Price");
if(categoryName.equals("标准洗车")){
vars.put("Marketing_Price",price);
break;






