代码之家  ›  专栏  ›  技术社区  ›  Shawn

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

  •  1
  • Shawn  · 技术社区  · 7 年前

    "{\"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 回复  |  直到 7 年前
        1
  •  1
  •   Shawn    7 年前

    明白了。

    * 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