KarateException缺少路径中的属性-JSON [英] KarateException Missing Property in path - JSON

查看:60
本文介绍了KarateException缺少路径中的属性-JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图匹配响应中的特定变量,并尝试如下.但我说KarateException Missing Property in path $['Odata']时出现错误.我的问题是:我们如何进行修改,以免出现此错误?

I was trying to match particular variable from response and tried as below. But im getting error saying KarateException Missing Property in path $['Odata']. My question is: how we can modify so that we won't get this error?

功能:

And match response.@odata.context.a.b contains '<b>'

示例:

|b|
|b1  |
|b2  |

回复为

{
    "@odata.context": "$metadata#Accounts",

    "a": [
            {
                "c": 145729,
                "b": "b1",
                "d": "ON",
            },
            {
                "c": 145729,
                "b": "b2",
                "d": "ON",
            }
        ]
 }

推荐答案

我认为您对JSON的结构感到困惑.还要注意,当JSON键具有特殊字符时,您需要更改在路径表达式中使用它们的方式.您可以尝试将以下内容粘贴到新方案中,然后查看其工作情况:

I think you are confused with the structure of your JSON. Also note that when the JSON key has special characters, you need to change the way you use them in path expressions. You can try paste the below in a new Scenario and see it work:

* def response =
"""
{
"@odata.context": "$metadata#Accounts",
"a": [
    {
        "c": 145729,
        "b": "b1",
        "d": "ON",
    },
    {
        "c": 145729,
        "b": "b2",
        "d": "ON",
    }
]
}
"""
* match response['@odata.context'] == '$metadata#Accounts'
* match response.a[0].b == 'b1'
* match response.a[1].b == 'b2'

这篇关于KarateException缺少路径中的属性-JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆