How to parse JSON response using Loadruner

Action()
{
    
    char* response;
  
    web_reg_save_param("Json_Response","LB=","RB=","SaveOffset=218",LAST);
  
      
        web_custom_request("GETAPI",
        "URL=http://appwa-dvpapi-q02.azurewebsites.net/api/offerv210/65758585/GA/30338/Skoal_ICA/All",
        "Resource=1",
        "RecContentType=application/json",
        "Referer=",
        "Snapshot=t1.inf",
        LAST);
  
  
    lr_save_string(lr_eval_string("{Json_Response}"),"reponse");
  
    lr_eval_json("Buffer={reponse}""JsonObject=json_obj"LAST);
  
    lr_json_stringify("JsonObject=json_obj","Format=indented","OutputParam=Result",LAST);
 
    lr_output_message("Indented JSON is : %s"lr_eval_string("{Result}"));
  
  
     // lr_eval_json("Buffer={Result}","JsonObject=json_obj1", LAST);    

    // Save result in parameter "title"
  
   lr_json_get_values("JsonObject=json_obj","ValueParam=id","QueryString=$.offers[*].id","SelectAll=Yes",LAST);
 
   //save result in parameter "offerType".
 
   lr_json_get_values("JsonObject=json_obj","ValueParam=offerType","QueryString=$.offers[*].offerType","SelectAll=Yes",LAST);
 
   //save result in parameter "discountCode"
 
   lr_json_get_values("JsonObject=json_obj","ValueParam=offerType","QueryString=$.offers[*].discountCode","SelectAll=Yes",LAST);
 
   //save result in parameter "appliesTo"
 
   lr_json_get_values("JsonObject=json_obj","ValueParam=offerType","QueryString=$.offers[*].appliesTo","SelectAll=Yes",LAST);
 
  //save results in parameter "offerStatusMessage"

  lr_json_get_values("JsonObject=json_obj","ValueParam=offerStatusMessage","QueryString=$.offers[*].offerStatusMessage","SelectAll=Yes",LAST);


//  â\x80\x99

//web_reg_save_param("Status Message","LB=","RB=","Savelen=3","Saveoffset=9",LAST);


  
   // lr_convert_string_encoding("results",LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8, "Result"); 
  
   return 0;
}


Output:
=======================================================================
     {
            "id": "K7704",
            "offerType": "OFL",
            "quantity": "1",
            "text": "(1) $1.00 Off a Can",
            "discountCode": "60J40A",
            "itemValue": 1.0,
            "currencySymbol": "$",
            "currencySymbolPlacement": "pre",
            "itemValueText": "(1) $1.00 Off a Can",
            "appliesTo": "DROPCATCH MINI BAR BLADES",
            "isDigital": false,
            "pointsCost": 0,
            "physicalDeliveryOption": true,
            "offerStatusCode": "000",
            "offerStatusMessage": "Success"
        }
    ]
}
Action.c(31): Notify: Saving Parameter "id_1 = 1820000001".
Action.c(31): Notify: Saving Parameter "id_2 = 1820000002".
Action.c(31): Notify: Saving Parameter "id_3 = F7234".
Action.c(31): Notify: Saving Parameter "id_4 = 20836000000".
Action.c(31): Notify: Saving Parameter "id_5 = 7K025".
Action.c(31): Notify: Saving Parameter "id_6 = B9297".
Action.c(31): Notify: Saving Parameter "id_7 = 7K031".
Action.c(31): Notify: Saving Parameter "id_8 = 7K024".
Action.c(31): Notify: Saving Parameter "id_9 = B9296".
Action.c(31): Notify: Saving Parameter "id_10 = 7K030".
Action.c(31): Notify: Saving Parameter "id_11 = K7705".
Action.c(31): Notify: Saving Parameter "id_12 = K7704".
Action.c(31): Notify: Saving Parameter "id_count = 12".
Action.c(31): lr_json_get_values succeed, 12 matches
Action.c(35): Notify: Saving Parameter "offerType_1 = BBK".
Action.c(35): Notify: Saving Parameter "offerType_2 = BBK".
Action.c(35): Notify: Saving Parameter "offerType_3 = CTM".
Action.c(35): Notify: Saving Parameter "offerType_4 = BBK".
Action.c(35): Notify: Saving Parameter "offerType_5 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_6 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_7 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_8 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_9 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_10 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_11 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_12 = OFL".
Action.c(35): Notify: Saving Parameter "offerType_count = 12".
Action.c(35): lr_json_get_values succeed, 12 matches
Action.c(39): Notify: Saving Parameter "offerType_1 = 182000MCR".
Action.c(39): Notify: Saving Parameter "offerType_2 = 182000MCR".
Action.c(39): Notify: Saving Parameter "offerType_3 = 18J30A".
Action.c(39): Notify: Saving Parameter "offerType_4 = 18J40I".
Action.c(39): Notify: Saving Parameter "offerType_5 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_6 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_7 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_8 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_9 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_10 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_11 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_12 = 60J40A".
Action.c(39): Notify: Saving Parameter "offerType_count = 12".
Action.c(39): lr_json_get_values succeed, 12 matches
Action.c(43): Notify: Saving Parameter "offerType_1 = Skoal Offline (MC Reship)".
Action.c(43): Notify: Saving Parameter "offerType_2 = Skoal Offline (MC Reship)".
Action.c(43): Notify: Saving Parameter "offerType_3 = ON ANY STYLE OF SKOAL®".
Action.c(43): Notify: Saving Parameter "offerType_4 = SKOAL QFTB BBK Offer".
Action.c(43): Notify: Saving Parameter "offerType_5 = Skoal Offline (Web Issue)".
Action.c(43): Notify: Saving Parameter "offerType_6 = Skoal Price Relief (Handraiser)".
Action.c(43): Notify: Saving Parameter "offerType_7 = Skoal Complaint (Empowerment)".
Action.c(43): Notify: Saving Parameter "offerType_8 = Skoal Offline (Web Issue)".
Action.c(43): Notify: Saving Parameter "offerType_9 = Skoal Price Relief (Handraiser)".
Action.c(43): Notify: Saving Parameter "offerType_10 = Skoal Complaint (Empowerment)".
Action.c(43): Notify: Saving Parameter "offerType_11 = POCKET SPITOON".
Action.c(43): Notify: Saving Parameter "offerType_12 = DROPCATCH MINI BAR BLADES".
Action.c(43): Notify: Saving Parameter "offerType_count = 12".
Action.c(43): lr_json_get_values succeed, 12 matches
Action.c(47): Notify: Saving Parameter "offerStatusMessage_1 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_2 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_3 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_4 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_5 = ATCâ\x80\x99s residence address restricts the availability of this offer".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_6 = ATCâ\x80\x99s residence address restricts the availability of this offer".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_7 = ATCâ\x80\x99s residence address restricts the availability of this offer".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_8 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_9 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_10 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_11 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_12 = Success".
Action.c(47): Notify: Saving Parameter "offerStatusMessage_count = 12".
Action.c(47): lr_json_get_values succeed, 12 matches

No comments:

Post a Comment