我尝试使用 jsonPath 读取 json 的内容,但出现错误。
这里的junit测试方法:
mockMvc.perform(get("/path")
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(1)))
.andExpect(jsonPath("$.name", is("NAME")))
.andReturn().getResponse().getContentAsString();
这是请求返回给我的内容:
[{"id":1,"name":"NAME","....}, ....}]
我收到了这个错误:
No value for JSON path: $.id, exception: Path 'id' is being applied to an array. Arrays can not have attributes.
有人可以帮助我。
谢谢