我正在尝试从 json 文件中获取对象数组,但遇到了问题。
path.get("wgcTournaments.items")
我应该使用什么路径来获取项目中的所有项目(item0、item1、item2 ...)?
您能给我一些建议吗?
Json 示例
{
"wgcTournaments": {
"items": {
"jcr:primaryType": "nt:unstructured",
"item0": {
"jcr:primaryType": "nt:unstructured",
"test": "test",
"test1": "test1"
},
"item1": {
"jcr:primaryType": "nt:unstructured",
"test": "test",
"test1": "test1"
},
"item2": {
"jcr:primaryType": "nt:unstructured",
"test": "test",
"test1": "test1"
},
"item3": {
"jcr:primaryType": "nt:unstructured",
"test": "test",
"test1": "test1"
}
}
}
}
从 items 对象中过滤 item 的最佳方法,但我不明白如何使用 json 路径来做到这一点。
最佳答案
终于我找到了我的问题的解决方案。
如果你想从项目中获取项目,你需要使用这个 json 路径
path.getObject("wgcTournaments.items*.
find{it.key.startsWith('item')}.value",ItemClass[].class);
注意: 这是 RestAssured,他使用 Gpath 更多详细信息,您可以在这里找到 http://docs.groovy-lang.org/latest/html/documentation/#_gpath
关于java - 放心 JsonPath : How to filter json objects from json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41223035/