java代码抛出“无效的json表达式”,但在线计算器显示正确的输出

t2a7ltrp  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(143)

当我在中尝试$.[?(@.userid=='1')].title时https://jsonpath.com/,得到了预期的结果。但当我在代码中使用相同的表达式时,我得到了错误。

@Test
public void restPost2(){
    RestAssured.baseURI = "https://jsonplaceholder.typicode.com/posts";
    RequestSpecification req = RestAssured.given().log().all();
    String res1 = req.given().when().get().then().extract().asString();
    JsonPath js = new JsonPath(res1);
    System.out.println("specific title : " + js.get("$.[?(@.userId == '1')].title"));
}

谁能告诉我为什么我的代码会抛出以下错误:

java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: unexpected token: [ @ line 1, column 29.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题