空手道匹配错误:匹配失败:等于$ |数据类型不匹配(其他:地图)
我有一个场景,可以从文件中读取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
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"}"
}
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
db.readrow()
显然正在返回不是JavaMAP
或List
的东西,因此,如果您修复了自己的路线。请参阅文档: https://github.com/karatebs/karatebabs/karate#type-conversion
* print testaddress.address
的结果清楚地表明,这不是空手道可以自动转换为JSON的东西,否则输出将正确缩进。现在,如果您知道被返回的任何内容的
toString()
在捏中,可以做到这一点:The
db.readRow()
is clearly returning something that's NOT a JavaMap
orList
, 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: