英文:
Rest-assured. get value from another value
问题
"results": [
{
"id": "1",
"name": "YYY",
"shortName": "Y"
},
{
"id": "2",
"name": "XXX",
"shortName": "X"
},
{
"id": "3",
"name": "ZZZ",
"shortName": "Z"
}
]
我想在发送名称值时获取ID值。例如,如果名称为ZZZ,则在这种情况下返回ID值3,使用Rest Assured。
英文:
I have a json response something like this:
"results": [
{
"id": "1",
"name": "YYY",
"shortName": "Y"
},
{
"id": "2",
"name": "XXX",
"shortName": "X"
},
{
"id": "3",
"name": "ZZZ",
"shortName": "Z"
}
]
I want to get id value when I send name value. For example if name = ZZZ return me id value in this case 3 using rest assured
答案1
得分: 2
Json路径 json-path-2.9.0
与 rest-assured
import static com.jayway.restassured.path.json.JsonPath.from;
下面是JsonPath查询:
from(response).getList("results.findAll { it.name=='ZZZ' }.id").toString() //返回 3
from(response).getList("results.findAll { it.name=='XXX' }.id").toString() //返回 2
英文:
Json path json-path-2.9.0
with rest-assured
import static com.jayway.restassured.path.json.JsonPath.from;
below JsonPath query
from(response).getList("results.findAll { it.name=='ZZZ' }.id").toString() //returns 3
from(response).getList("results.findAll { it.name=='XXX' }.id").toString() //returns 2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论