我需要从JSON响应中读取键和值,并使用机器人框架代码将其存储为JSON格式。
我试过机器人框架代码
JSON RESPONSE:
{
"data": {
"resources": {
"edges": [
{
"node": {
"tags": [],
}
},
{
"node": {
"tags": [
{
"name": "app",
"value": "e2e"
},
{
"name": "Cost",
"value": "qwerty"
}
}
}, {
"node": {
"tags": [
{
"name": "app",
"value": "e2e"
},
{
"name": "Cost",
"value": "qwerty"
},
{
"name": "test",
"value": "qwerty"
}
}
}
]
}
}
}
我的机器人代码:
${tag_Count}= 3 ##Since there are 3 tags variable in response
: FOR ${item} IN RANGE 0 ${tag_Count}
\ ${resourceName}= run keyword if ${tag_Count} > 0 set variable ${readName['name']}
\ log to console ${resourceName}-forloop
\ ${resourceName_length}= get length ${resourceName}
\ ${readkey}= set variable ${tag_variable[${item}]['name']}
\ ${readvalue}= set variable ${tag_variable[${item}]['value']}
set to dictionary ${dict} ${readkey} ${readvalue}
set suite variable ${dict}
${req_json} Json.Dumps ${dict}
Create File response.json ${req_json}
我需要在json文件中以这种格式的响应。我怎么做?
{
"name": "app",
"value": "e2e"
},
{
"name": "Cost",
"value": "qwerty"
},
{
"name": "app",
"value": "e2e"
},
{
"name": "Cost",
"value": "qwerty"
},
{
"name": "test",
"value": "qwerty"
}
我想单独获取标签名称和值并存储在JSON文件中。我只能将最后一个标签响应存储在JSON文件中。
1条答案
按热度按时间flvtvl501#
这是我的json:
这是我的代码(RFW中的JSONPath):
希望这能帮上忙。