【问题标题】:How to get the required content from a JSON string如何从 JSON 字符串中获取所需的内容
【发布时间】:2013-03-01 08:04:53
【问题描述】:

我在 Robot Frame Work 中有一个具有以下格式的 Json 响应正文的变量

{
   "jsonrpc": "2.0",
   "id": "787878",
   "result":
   {
       "content":
       [
           {
               "id": 30,
               "userID": "user",
               "eventType":
               {
                   "name": "test"
               },
               "timestamp": "2013-03-13T11:00:28.537Z",
               "source": "Service",
               "reason": null,
               "comment": null,
               "dataCache":
               {
                   "lastLogin":
                   {
                       "id": 103,
                       "fieldName": "value1",
                       "newValue": "Wed Mar 13 07:00:28 EDT 2013",
                       "oldValue": null,
                       "type": "java.util.Date",
                       "auditEvent": null
                   }
               },
               "authority": "authenticate",
               "auditedObject": null
           }
       ],
       "pageNumber": 0,
       "pageSize": 99,
       "numberOfElements": 1,
       "totalElements": 1,
       "lastPage": true,
       "totalPages": 1
   }

}

SO from this How can I get the content only datacache 如下所示

{
   "lastLogin":
   {
       "id": 103,
       "fieldName": "value1",
       "newValue": "Wed Mar 13 07:00:28 EDT 2013",
       "oldValue": null,
       "type": "java.util.Date",
       "auditEvent": null
   }
},

如果我使用像 ${variable['result']['content']} 这样的变量,我将在内容中获得整个正文但我只想要“DataCache”中的正文:

请帮我解决这个问题..

【问题讨论】:

  • 你不能再深入一点 ${variable['result']['content']['dataCache']}
  • 我试过这个 "${variable['result']['content']['dataCache']}" 但没用

标签: python python-2.7 selenium-webdriver robotframework


【解决方案1】:
${variable['result']['content'][0]['dataCache']}

这就是你要找的吗?也许你需要更多的 JSON 练习......

【讨论】:

  • 是的,这就是我要找的……谢谢天蝎座
【解决方案2】:
${variable['result']['content'][0]['dataCache']}

在我的情况下工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 2020-06-16
    • 2013-07-03
    相关资源
    最近更新 更多