首页 > 解决方案 > 如何通过另一个属性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"
    }
]

IDtitle属性获取对象的最佳方法是什么?

例如我需要找到ID“test3”。

我有 100 多个对象作为响应,并且很难手动找到它。

标签: javajsonrest-assured

解决方案


除了其他人评论的 2 个解决方案之外,我还添加了另一个解决方案。

import io.restassured.path.json.JsonPath;

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

推荐阅读