简体   繁体   English

当 RestAssured 响应只是一个没有名称的数组时如何编写 GPath 表达式

[英]How to write a GPath expression when the RestAssured response is simply an array with out a name

After my RestAssured code executed, I got a response body like this(which is valid, since I verified it in Postman also)在我的 RestAssured 代码执行后,我得到了一个这样的响应体(这是有效的,因为我也在 Postman 中验证了它)

[
    {
        "team": null,
        "name": "Automation",
        "id": "977638c2-0095-42fb-a3fb-3ef442cc61e2"
    },
    {
        "team": null,
        "name": "Default",
        "id": "e9e0ab5d-0abf-402a-a747-612a4e9c7e25"
    }
]

Now I need to retrieve the id of a Json object for which the name is 'Automation'.现在我需要检索名称为“自动化”的 Json object 的 ID。 The line of code I wrote is like this which is returning null , which I can't understand.我写的代码行是这样的,它返回null ,我无法理解。

response.path("$.find{it.name == 'Automation'}.id");  (OR)
response.path("content.find{it.name == 'Automation'}.id");

Please correct my code, to return the correct value 977638c2-0095-42fb-a3fb-3ef442cc61e2请更正我的代码,以返回正确的值977638c2-0095-42fb-a3fb-3ef442cc61e2

You can use the query like this:您可以像这样使用查询:

response.path("find{it.name == 'Automation'}.id");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM