如何在loadrunner中提取json请求数据

问题描述 投票:0回答:3

我的 API 调用的 LR 响应数据包含以下详细信息。我需要将每个 UPC 获取到一个变量中,以便我可以在后续请求中使用它。我该怎么做呢?

这是一个json响应数据。

{
  "isRegistered": true,
  "points": 8383,
"Upcs": [
    "03546451",
    "03330067",
    "03332184",
    "03333822",
    "03334287",
    "06508814",
    "07433870",
    "06515393",
    "065153936666",
    "09836013",
    "09835870",
    "00081283 ",
    "01391343"
    ]

}
loadrunner
3个回答
1
投票

如果您使用的是LR 12.53,您可以使用最新的JSON API来解析JSON数据。 对于您的情况,

lr_eval_json("Buffer={JSON_INPUT}", "JsonObject=json_obj", LAST);
lr_json_get_values("JsonObject=json_obj", "ValueParam=upcs", "QueryString=$.Upcs", "SelectAll=Yes", LAST);

upcs 值将存储在参数 upcs_1、upcs_2、... 中


0
投票

使用 LR 12.53 中的 web_reg_save_param_json 函数可以轻松完成此操作。

web_reg_save_param_json(
    "ParamName=nameParam",
    "QueryString=$.Upcs.[*]",
    "SEARCH_FILTERS",
    "Scope=Body", "SelectAll=Yes",
    "LAST");

反应是这样的。

function.h(29): Notify: Saving Parameter "nameParam_1 = 00662772".    function.h(29): Notify: Saving Parameter "nameParam_2 = 00667488".    function.h(29): Notify: Saving Parameter "nameParam_3 = 00667489".    function.h(29): Notify: Saving Parameter "nameParam_4 = 00667490".    function.h(29): Notify: Saving Parameter "nameParam_5 = 21537499".    function.h(29): Notify: Saving Parameter "nameParam_6 = 06337500".    function.h(29): Notify: Saving Parameter "nameParam_7 = 06057501".    function.h(29): Notify: Saving Parameter "nameParam_8 = 02107502".    function.h(29): Notify: Saving Parameter "nameParam_9 = 21537503".    function.h(29): Notify: Saving Parameter "nameParam_10 = 06017504".    function.h(29): Notify: Saving Parameter "nameParam_11 = 02117505".    function.h(29): Notify: Saving Parameter "nameParam_12 = 06017506".    function.h(29): Notify: Saving Parameter "nameParam_13 = 01097507".    function.h(29): Notify: Saving Parameter "nameParam_14 = 01137508".    function.h(29): Notify: Saving Parameter "nameParam_count = 14".

0
投票

保存多场比赛

web_reg_save_param_json
函数支持数组类型参数。当您指定
SelectAll=Yes
时,所有匹配项都会保存在数组中。数组的每个元素都由
ParamName_index
表示。在以下示例中,参数名称为 A:

web_reg_save_param_json("ParamName= A", "QueryString=$..arguments.additional_context[0].name", "SelectAll=Yes", LAST );

第一个匹配项保存为 A_1,第二个匹配项保存为 A_2,依此类推。您可以使用以下术语检索匹配的总数:

ParamName_count
。例如,要检索保存到参数数组的匹配总数,请使用:

TotalNumberOfMatches=atoi(lr_eval_string("{A_count}"));

更多详细信息请参阅:https://admhelp.microfocus.com/vugen/en/2022-2022-r2/help/function_reference/Content/FuncRef/web/lrFr_web_reg_save_param_json.htm?cshid=web_reg_save_param_json#Saving_Multiple_Matches

© www.soinside.com 2019 - 2024. All rights reserved.