请保证使用JSONPATH中的列表中的最后一个元素
我想使用重新安排来测试返回对象的JSON列表的端点。如何使用RETASER的JSONPATH验证列表中最后一个对象的内容?
示例返回值:
[
{
"foo": "bar"
},
{
"foo": "brazz"
}
]
我尝试使用否定索引: body(“ [ - 1] .foo”,qualto(“ brazz”))
,但这不起作用,因为请放心,认为“ [ - 1] .foo”
成为一个空列表。
如何使用JSONPATH语法访问列表的最后一个元素?
I want to use RestAssured to test an endpoint that returns a JSON list of objects. How can I verify the contents of the last object in the list using RestAssured JsonPath?
Example return value:
[
{
"foo": "bar"
},
{
"foo": "brazz"
}
]
I tried using negative indices:body("[-1].foo", equalTo("brazz"))
but that does not work, as Rest assured considers "[-1].foo"
to be an empty list.
How can I access the last element of a list with JsonPath Syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用
last()
获取最后一项。Yes, you can use
last()
to get the last item.