如何使用 rest Assured 从 api 响应中获取值

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

我新来的放心。我有一个响应 json,如下所示。我在一个数组中有多个嵌套的 json,其中包含特定商家的支出详细信息。我只需要获取 Netflix 的花费值。我如何检查 Netflix 仅获得绝对值的条件?

{
"data": {
    "content": [
        {
            "absolute": 1800091.5124980211,
            "percentage": 99.9,
            "count": 79,
            "currency": "USD",
            "element": {
                "merchantBrandName": "Bliz",
                "merchantLogo": "png"
            }
        },
        {
            "absolute": 2170.220006465912,
            "percentage": 0.1,
            "count": 141,
            "currency": "USD",
            "element": {
                "merchantBrandName": "Netflix",
                "merchantLogo": "png1"
            }
        },
        {
            "absolute": 30.240000128746033,
            "percentage": 0.0,
            "count": 27,
            "currency": "USD",
            "element": {
                "merchantBrandName": "Wal",
                "merchantLogo": "svg"
            }
        },
        {
            "absolute": 22.59999990463257,
            "percentage": 0.0,
            "count": 20,
            "currency": "USD",
            "element": {
                "merchantBrandName": "MAL",
                "merchantLogo": "dining.svg"
            }
        },
        {
            "absolute": 19.800000429153442,
            "percentage": 0.0,
            "count": 18,
            "currency": "USD",
            "element": {
                "merchantBrandName": "Ub",
                "merchantLogo": "9XrD.png"
            }
        },
        {
            "absolute": 15.680000066757202,
            "percentage": 0.0,
            "count": 14,
            "currency": "USD",
            "element": {
                "merchantBrandName": "way",
                "merchantLogo": "iZ.png"
            }
        }
    ],
    "page": {
        "size": 6,
        "totalElements": 6,
        "totalPages": 1,
        "number": 1
    }
}

}

JsonPath js = new JsonPath(response);
js.get(key).toString();

我曾经直接使用 JsonPath 获取值,但现在它是我需要获取的基于条件的值。

这里我需要获取键“absolute”的值,其中 merchantBrandName 是 Netflix,它又在一个嵌套的 json 中

java json rest rest-assured jsonparser
© www.soinside.com 2019 - 2024. All rights reserved.