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

时间:2019-11-12 09:07:09

标签: python json robotframework

我需要从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文件中。

0 个答案:

没有答案