如何使用robotframework关键字从JSON字符串中获取所需参数

如何使用robotframework关键字从JSON字符串中获取所需参数,json,robotframework,Json,Robotframework,下面是我的JSON响应字符串 { "macKey": "This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "subject": "delivery@token.com", "audience": "qed:test", "expirationTime": "2016-03-09T23:07:52Z", "notBeforeTime": "2016-03-09T23:07:52Z", "jwtId": ""

下面是我的JSON响应字符串

{
 "macKey": "This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long",
"subject": "delivery@token.com",
"audience": "qed:test",
"expirationTime": "2016-03-09T23:07:52Z",
"notBeforeTime": "2016-03-09T23:07:52Z",
"jwtId": "",
"permissions": [
"MANAGE_SYSTEM"
],
"useCompactPermissions": false,
"url": "http://172.30.2.155:8080/",
"generatedToken": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0Iiwic3ViIjoiZGVsaXZlcnlAdG9rZW4uY29tIiwiYXVkIjoicWVkOnRlc3QiLCJxZWRwIjpbIm1hbmFnZVN5c3RlbSJdLCJleHAiOjE0NTc1NjQ4NzJ9.8KlDoK-t6HoOth3na2x6drEAFfXCGLKLt3aAMGg0r0U",
"qeda": null,
"qedp": [
"manageSystem"
],
"issueTime": "2016-03-09T09:34:40Z"
}
从上面的一个示例中,我需要获取generatedToken值。

使用RequestsLibrary中的“to JSON” 如果使用获取JSON数据,可以使用关键字将其转换为对象。然后可以使用访问各个字段

例如:

| | ${json}= | To JSON | ${response}
| | log to console | \n the token is ${json["generatedToken"]}
使用内置库中的“评估” 您可以使用关键字运行标准python函数将json字符串转换为对象。只要数据没有任何带三重引号的字符串,这将起作用:

| | ${json}= | Evaluate | json.loads('''${response}'''} | json
| | log to console | \n the token is ${json["generatedToken"]}
你可以用 然后你可以这样得到它:

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

${Ref_Id_Value}    Get Json Value    ${POSTResp.content}    /doInitiateFundsTransferResponseBody/transactionInformation/transactionReferenceNumber
我认为,您可以使用
获取Json值
方法