java - 如何通过另一个属性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"
}
]
ID
按title
属性获取对象的最佳方法是什么?
例如我需要找到ID
“test3”。
我有 100 多个对象作为响应,并且很难手动找到它。
解决方案
除了其他人评论的 2 个解决方案之外,我还添加了另一个解决方案。
import io.restassured.path.json.JsonPath;
Response res = ...;
int id = JsonPath.from(res.asString()).get("find {it.title == 'test3'}.id");
推荐阅读
- javascript - 计算提示答案时遇到问题
- c# - .NET Core (2.1) Web API 控制器接受请求 url 中的所有内容作为参数
- entity-framework - 实体框架对本地数据执行原始 SQL
- android - 如何仅删除 Facebook 登录按钮上的 Facebook 徽标
- linux - Monit无法启动进程:(退出状态0)--无输出
- ansible - 如何通过ansible将指定的子文件夹复制到目的地
- wordpress - 鼠标滚轮与滑块旋转的交互
- maven - Apache Curator ZooKeeper - KeeperErrorCode = 未实现,错误
- ios - Swift 函数参数命名
- python - 使用 tf.data.Dataset.from_generator 时出现“SystemError:没有设置异常的错误返回”