简体   繁体   English

使用 MockMvc.jsonpath() 方法测试 API 响应正文时如何在括号 [] 内输入

[英]How to enter inside a bracket [] when testing API response body using MockMvc .jsonpath() method

I am new to MockMvc and jsonpath.我是 MockMvc 和 jsonpath 的新手。 I did some API testing with rest assured and hamcrest matchers before but I can't figure something out.我之前使用 rest 和 hamcrest 匹配器进行了一些 API 测试,但我无法弄清楚。

How can I get inside the bracket for this response body?如何进入此响应正文的括号内?

在此处输入图像描述

As you can see the response body contains List of users hence the brackets.. So I don't know what to write inside my expression so I have just written "" but it seems that triggers compiler error.如您所见,响应正文包含用户列表,因此包含括号..所以我不知道在我的表达式中写什么,所以我刚刚写了“”,但似乎触发了编译器错误。

Any help is appreciated任何帮助表示赞赏

Best,最好的,

I should've used expression as "$.[0]"我应该将表达式用作“$.[0]”

This solved my problem.这解决了我的问题。

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

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