我正在使用非静态导入
JsonPath jp = response.jsonPath();
System.out.println(jp.get("data?(@.id>14).employee_name").toString());
对于如下所示的 JSON:
{"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61","profile_image":""},{"id":"2","employee_name":"Garrett Winters","employee_salary":"170750","employee_age":"63","profile_image":""}]}
当我尝试运行它时,我得到以下错误:
java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: expecting EOF, found '[' @ line 1, column 31.
data[?(@.id>14)].employee_name
^
1 error
有人可以指导我为什么会抛出此错误吗?
我怀疑该语法是否正确,但是,您应该使用以下语法
另请注意,id 是响应中的字符串,因此您必须将其包含在引号中
js.get("data.find {it.id > '14'}.employee_name").toString();