[英]How to extract body attribute by another attribute REST-ASSURED JAVA
I have following response after GET request : 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"
}
]
What is the best way to get object ID
by title
attribute?通过
title
属性获取对象ID
的最佳方法是什么?
For example I need to find ID
of "test3".例如,我需要找到“test3”的
ID
。
I have 100 + objects in response and it's hard to find it manually.我有 100 多个对象作为响应,并且很难手动找到它。
Beside 2 solutions that others commented, I add another one.除了其他人评论的 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.