【问题标题】:karate how to parse stringified json response空手道如何解析字符串化的 json 响应
【发布时间】:2018-06-13 06:34:08
【问题描述】:

我收到了这样的回复。

"{\"statusCode\":204,\"output\":\"{\\n  \\\"Id\\\" : \\\"884d39b8-4afc-4ee3-807a-9d6dbde8c390\\\",\\n  \\\"temp\\\" : \\\"33\\\",\\n  \\\"lastUpdateAuthor\\\" : null\\n}\"}"

我怎样才能解析这个响应并做类似的事情

* def expectedOutput = 
"""
{
      "Id": "884d39b8-4afc-4ee3-807a-9d6dbde8c390",
      "temp": "33",
      "lastUpdateAuthor": null
    }
  Scenario: Testing a PUT endpoint with request body
    Given path 'v0'
    And request input
    When method put
    Then match status 200
    And match JSON.parse(JSON.parse(response).output) == expectedOutput

最后一行代码被空手道跳过了。

有什么意见吗?

【问题讨论】:

    标签: karate


    【解决方案1】:

    想通了。

    * def expectedOutput = 
    """
    {
      "Id": "884d39b8-4afc-4ee3-807a-9d6dbde8c390",
      "temp": "33",
      "lastUpdateAuthor": null
    }
    """
      Scenario: Testing a PUT endpoint with request body
        Given path 'v0'
        And request input
        When method put
        Then match status 200
        And json convertJSON = $
        And json convertJSON = convertJSON.output
        And match convertJSON.latitude == expectedOutput
    

    成功了。

    【讨论】:

    • 太棒了!一旦系统允许您这样做,请务必将您自己的答案标记为“已接受”。谢谢!
    猜你喜欢
    • 2019-02-17
    • 1970-01-01
    • 2015-10-02
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多