3

这是我的 JSON:

[
{
    "id": 9741962,
    "name": "getName",
    "isActive": true
},
{
    "id": 1,
    "name": "New",
    "isActive": true
}
]

我想使用 jsonPath 获取所有名称为 :getName 的对象如何使用 JsonPath 来完成(放心的 onw)

我试试这个

JsonPath.with(jsonResponse).get("findAll { a -> a.name == getName  }");

但我收到错误。

java.lang.IllegalArgumentException: No such property: sdfsdf for class: Script1

谢谢。

4

2 回答 2

6

好的,我找到了,需要添加撇号。

JsonPath.with(jsonResponse).get("findAll { a -> a.name == 'getName' }");

于 2014-08-03T08:22:49.597 回答
2

您需要设置参数。尝试

JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name  }")
于 2014-07-31T14:39:00.870 回答