空手道匹配错误:匹配失败:等于$ |数据类型不匹配(其他:地图)

发布于 2025-02-09 08:53:58 字数 1373 浏览 1 评论 0原文

我有一个场景,可以从文件中读取JSON字段,并将其与另一个JSON字段进行比较。当我进行比赛时,它说文件中的字段是键入“其他”。很抱歉屏幕截图,但我认为印刷语句很有帮助。

这是文件,我不确定我是否可以在不使用文件的情况下提供示例,因为当我在方案中设置字段时,它的工作方式有所不同,地址的值则是Match语句中的字符串。它必须与从读取行返回的数据有关吗?这就是数据的样子,从读取行回来: { “地址”:“ {“街”:“ 123 Main Street”,“ City”:“ Queens”,“ state”:“ NY”}“” }

Scenario: test error for stack overflow
  * def testAddress = db.readRow("select address from json_issue where person = 'Carole'")
  * print testAddress.address
  * def jsonAddressMatch =
  """
  {
    "street":"123 Main Street",
    "city": "Queens",
    "state": "NY"
  }
  """
  * print jsonAddressMatch
  * match testAddress.address == jsonAddressMatch

这是第一个测试的结果

我试图看看是否可以将其转换为JSON,以为它没有被解释为JSON。我添加了这两行,但是值是一个字符串,因此它仍然不是正确的类型。

     * json addressObject = testAddress.address
     * match addressObject.value == jsonAddressMatch 

这是使用“ JSON”转换的第二个测试结果

I have a scenario that reads a json field from a file and compares it to another json field. When I do the match, it says the field from the file is type "other". Sorry for the screen shots, but I think the print statements are helpful.

This is the file, I am not sure if I can provide an example without using the file because when I set the field in the scenario, it works differently, the value of address is then a string in the match statement. It must have something to do with the data returned from the read row? This is what the data looks like that comes back from the read row:
{
"address": "{"street":"123 Main Street", "city":"Queens", "state":"NY"}"
}
file with example in it

Scenario: test error for stack overflow
  * def testAddress = db.readRow("select address from json_issue where person = 'Carole'")
  * print testAddress.address
  * def jsonAddressMatch =
  """
  {
    "street":"123 Main Street",
    "city": "Queens",
    "state": "NY"
  }
  """
  * print jsonAddressMatch
  * match testAddress.address == jsonAddressMatch

This is the first test's results
test 1

I tried to see if I could convert it to json thinking it was not being interpreted as json. I added these two lines, but the value is a string so it still is not the correct type.

     * json addressObject = testAddress.address
     * match addressObject.value == jsonAddressMatch 

This is the second test's results using "json" to convert
test 2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2025-02-16 08:53:58

db.readrow()显然正在返回不是Java MAPList 的东西,因此,如果您修复了自己的路线。

请参阅文档: https://github.com/karatebs/karatebabs/karate#type-conversion

* print testaddress.address的结果清楚地表明,这不是空手道可以自动转换为JSON的东西,否则输出将正确缩进。

现在,如果您知道被返回的任何内容的toString()在捏中,可以做到这一点:

* def testAddress = karate.fromString(testAddress)

The db.readRow() is clearly returning something that's NOT a Java Map or List, so if you fix that you are on your way.

Refer the docs: https://github.com/karatelabs/karate#type-conversion

The result of * print testAddress.address clearly shows that it is NOT something Karate could auto-convert to JSON, else the output would have been indented correctly.

Now, in a pinch if you know that the toString() of whatever is being returned gives you valid JSON, you can do this:

* def testAddress = karate.fromString(testAddress)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文