无法过滤掉 jsonPath 中的值

问题描述 投票:0回答:1

我在 jsonpath 上工作,我需要为下面的特定国家/地区获取值是给定的 json。

{
    "homeCountry": "USA",
    "internationalControlDetails": [
        {
            "address": {
                "city": null,
                "country": "Canada",
                "county": null,
                "state": null,
                "zipCode": null
            },
            "dateRange": {
                "endDate": null,
                "startDate": null
            },
            "isHomeCountry": false,
            "regionId": null,
            "locationControlId": 649289
        },
        {
            "address": {
                "city": null,
                "country": "United States",
                "county": null,
                "state": null,
                "zipCode": null
            },
            "dateRange": {
                "endDate": null,
                "startDate": null
            },
            "isHomeCountry": true,
            "regionId": null,
            "locationControlId": 837251
        }
    ],
    "locationShieldState": "DISABLED",
    "regionControlDetails": []
}

对于给定的 json,我需要获取特定国家/地区的 locationControlId。我试过 $.internationalControlDetails.[?(@.country=='Canada')].locationControlId。但它不起作用。

我试过 $.internationalControlDetails.[?(@.country=='Canada')].locationControlId 但它不起作用。

我期待获取特定国家(如加拿大、美国)的 locationControlId

jsonpath rest-assured-jsonpath json-path-expression
1个回答
0
投票

你的路径应该是

$.internationalControlDetails.[?(@.address.country=='Canada')].locationControlId

注意本地路径中的

address

其他一切看起来都不错。

© www.soinside.com 2019 - 2024. All rights reserved.