Parsing JSON output in Robot framework [TypeError: expected string or buffer]

Parsing JSON output in Robot framework [TypeError: expected string or buffer]

我有这样的 JSON 输出:

{
  "output": {
    "ParentKey": {
      "key": "9b92e663a66c0cc1",
      "id": "uid=26"
    }
  }
}

我正在尝试获取密钥的内容,即:9b92e663a66c0cc1

假设 ${output} 有这个 JSON content/data..

这是我试过的代码:

${values}=    Evaluate    json.loads($output)    json
${response}    Evaluate      json.loads($values['output']['ParentKey'])  json
${key}  set variable  ${response['ParentKey']['key']}
[Return]  ${key}

我使用的是旧版机器人(低于 v3.2)

但是,我收到这样的错误

Evaluating expression 'json .loads (RF_VAR_values ['output']['ParentKey'])' failed: TypeError: expected string or buffer

如何在不出现上述错误的情况下获取密钥?

谢谢!!!


*** Settings ***
*** Variables ***

${our_json}   { "output": { "ParentKey": { "key": "9b92e663a66c0cc1", "id": "uid=26" } } }


*** Test Case ***
Test JSON
  ${values}=    Evaluate    json.loads($our_json)    json
  Log To Console    ${values}
  ${key}  set variable  ${values['output']['ParentKey']['key']}
  Log To Console   OUR KEY: ${key}

输出:

==============================================================================
Test
==============================================================================
Test JSON                                                             .{'output': {'ParentKey': {'key': '9b92e663a66c0cc1', 'id': 'uid=26'}}}
..OUR KEY: 9b92e663a66c0cc1
Test JSON                                                             | PASS |
------------------------------------------------------------------------------
Test                                                                  | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================