有没有办法获取多个json键和值并将其存储在RobotFramework的json文件中?

2024-09-25 00:36:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从json响应中读取键和值,并使用robot框架代码将其存储为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文件中存储最后一个标记响应。你知道吗


Tags: 代码namenodejsonappvaluetagcount