loadrunner12.55:循环打印lr_json_get_values()查询到的数据
处理的Json数据:
{ "success":true, "data":{ "current":1, "size":5, "pageSizes":[ 5, 10, 15, 20, 25 ], "total":4, "pageCount":0, "start":0, "end":0, "tablesArr":[ { "busiSceneId":"3a5ccca2-88ff-46cd-943e-b81d372fa629", "sceneName":"test3", "sceneDesc":"", "sceneTypeId":1, "createBy":"user_1", "createTime":"2021-05-28 16:43:00", "updateBy":"", "updateTime":"", "state":1 }, { "busiSceneId":"7eb81fcd-9db2-4233-a78f-a446ab01b722", "sceneName":"test2", "sceneDesc":"", "sceneTypeId":1, "createBy":"user_1", "createTime":"2021-05-28 16:42:56", "updateBy":"", "updateTime":"", "state":1 }, { "busiSceneId":"92b83c92-5d23-4bfc-878b-f1519ea75286", "sceneName":"test1", "sceneDesc":"", "sceneTypeId":1, "createBy":"user_1", "createTime":"2021-05-28 16:42:52", "updateBy":"", "updateTime":"", "state":1 }, { "busiSceneId":"d6c81dbb-3047-4266-8619-1971cf0450b2", "sceneName":"业务线配置新增", "sceneDesc":"业务线配置新增", "sceneTypeId":3, "createBy":"user_1", "createTime":"2021-03-05 10:28:00", "updateBy":"", "updateTime":"", "state":1 } ] }, "code":200, "message":"成功!" }
脚本实现:获取以上JSON数据中的所有busiSceneId字段取值,并循环打印出来。
Action1()
{
int i=1,busiSceneIdnum;
web_add_auto_header("Accept-Language",
"zh-Hans-CN,zh-Hans;q=0.5");
web_reg_save_param("queryResponseBody",
"LB=",
"RB=",
"Search=Body",
LAST);
web_custom_request("queryScene",
"URL=http://10.248.57.226:9010/user-center/uap-app-scene/queryScene",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=http://10.248.57.226:9010/U-C/",
"Snapshot=t23.inf",
"Mode=HTML",
"EncType=application/json;charset=utf-8",
"Body={\"current\":1,\"size\":10,\"busiSceneId\":\"\",\"sceneName\":\"\"}",
LAST);
// Create a Json object from a string.
lr_eval_json("Buffer={queryResponseBody}",
"JsonObject=json_obj_1", LAST);
busiSceneIdnum=lr_json_get_values("JsonObject=json_obj_1",//获取响应体所有busiSceneId字段值并保存到数组JinKuList中,用于后面删除的参数化
"ValueParam=JinKuList",
"QueryString=$.data.tablesArr[*].busiSceneId",
"SelectAll=Yes",
LAST);
while(i<=busiSceneIdnum){
lr_save_string(lr_paramarr_idx("JinKuList", i), "busiSceneId");//获取数组JinKuList中索引为i的值,后面可通过直接引用{busiSceneId}进行参数化
i=i+1;
}
return 0;
}
执行日志: