我想遍历json响应并获取id和name元素数据。我的反应json和代码,我正在尝试下面。有人可以让我知道我在做什么错误吗?如何迭代使用机器人框架的JSON数组
[
{
"id": 3,
"policyRevId": 3,
"busId": "POL_0003",
"revision": 1,
"name": "CIS Microsoft Windows Server 2012 R2 v2.2.1"
},
{
"id": 2,
"policyRevId": 2,
"busId": "POL_0002",
"revision": 1,
"name": "CIS SUSE Linux Enterprise Server 11 Benchmark v 2.0"
},
{
"id": 1,
"policyRevId": 1,
"busId": "POL_0001",
"revision": 1,
"name": "Payment Card Industry (PCI) Data Security Standard version 3.1"
}
]
*** Settings ***
Library RequestsLibrary
Library Collections
Library strings
*** Test case ***
Get Policy With Auth
@{auth}= Create List user pass
Create Session httpbin https://test123.com/ [email protected]{auth}
${resp}= Get Request httpbin uri=/policies/
:FOR ${i} in ${resp.json()}
\ Log ${i}
\ ${get_policy_id}= Get Variable Value ${resp.json()[i]['id']}
\ ${policy_name}= Get Variable Value ${resp.json()[i]['name']}
\ Log ${policy_id},${policy_name}
你得到一个错误?这段代码的输出与你期望的不同吗? –
@BryanOakley,我想迭代字典并获取id,name值。我得到输出为None。 resp.json()包含keyvalues对 – Madhu
当你记录'$ {i}'时,日志中显示的是什么? –