簡體   English   中英

如何通過另一個屬性REST-ASSURED JAVA提取body屬性

[英]How to extract body attribute by another attribute REST-ASSURED JAVA

GET請求后我有以下響應:

[
    {
        "id": 81,
        "userId": null,
        "title": "test1",
        "status": "TODO"
    },
    {
        "id": 564,
        "userId": null,
        "title": "test2",
        "status": "TODO"
    },
    {
        "id": 660,
        "userId": null,
        "title": "test3",
        "status": "TODO"
    }
]

通過title屬性獲取對象ID的最佳方法是什么?

例如,我需要找到“test3”的ID

我有 100 多個對象作為響應,並且很難手動找到它。

除了其他人評論的 2 個解決方案之外,我添加了另一個。

import io.restassured.path.json.JsonPath;

Response res = ...;
int id = JsonPath.from(res.asString()).get("find {it.title == 'test3'}.id");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM