2017-02-14 822 views
0

我的API調用的LR響應數據具有以下細節。我需要將每個UPC讀取到一個變量中,以便在隨後的請求中使用它。我該怎麼做呢?如何在loadrunner中提取json請求數據

這是一個JSON響應數據。

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

} 

回答

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); 

的的UPC值將被存儲在參數upcs_1,upcs_2,...

+0

嗨萊維,感謝您的回覆。我試過但這不起作用。 (42):通知:參數替換:參數「vFullResponse」=「{\ n」isRegistered「:true,\ n」pointsBalance「:25,\ n」offerUpcs「:[」03598030「, \ n「message」:「」,\ n「tier」:「Base」,\ n「stampCardBalances」:[{\ n「type」:「00640398」,\ n「amount」 (42):lr_eval_json成功 Action.c(45):Notify:Saving(n),n(n),{\ n「type」:「03006399」,\ n「amount」:0 \ n}] \ n}「 Action.c參數「offerUpcs_1 = [」03598030「,」03598030「]」。 –

+0

嘗試使用$ .Upcs [*]來查看它是否有效 – Levi

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".