首页 文章

空手道如何解析字符串化的json响应

提问于
浏览
1

我得到了这样的回复 .

"{\"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

空手道跳过最后一行代码 .

有什么输入?

1 回答

  • 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
    

    有效 .

相关问题