How to get a required parameter from JSON String using robotframework keyword

后端 未结 3 600
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-28 10:38

The following is my JSON response string

{
 \"macKey\": \"This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long\",
\"subject\": \"delivery@token.co         


        
相关标签:
3条回答
  • 2021-01-28 11:03

    Using "To JSON" from RequestsLibrary

    If you are using RequestsLibrary to get the JSON data, you can use the To JSON keyword to convert it to an object. You can then use extended variable syntax to access the individual fields.

    For example:

    | | ${json}= | To JSON | ${response}
    | | log to console | \n the token is ${json["generatedToken"]}
    

    Using "Evaluate" from the BuiltIn library

    You can use the Evaluate keyword to run the standard python function json.loads to convert a json string to an object. As long as the data doesn't have any triple-quoted strings, this will work:

    | | ${json}= | Evaluate | json.loads('''${response}'''} | json
    | | log to console | \n the token is ${json["generatedToken"]}
    
    0 讨论(0)
  • 2021-01-28 11:10
    ${Ref_Id_Value}    Get Json Value    ${POSTResp.content}    /doInitiateFundsTransferResponseBody/transactionInformation/transactionReferenceNumber
    

    You can use the Get Json Value method, I think.

    0 讨论(0)
  • 2021-01-28 11:25

    You can use robotframework-httplibrary then you can get it like this:

    ${value}= Get Json Value ${json} /generatedToken

    0 讨论(0)
提交回复
热议问题