我不确定我在这里做错了什么,我正在经历一段地狱般的时间,让它正常工作。使用此JSON:
{
"books": [
{
"category": "reference",
"author": {
"name": "Nigel Rees",
"age": 45
},
"title": "Sayings of the Century",
"price": 8.95,
"tax": 7.00
},
{
"category": "reference",
"author": {
"name": "Evelyn Waugh",
"age": 30
},
"title": "A cheap book",
"price": 6.00,
"tax": 3.00
}
]
}例如,我无法提取作者年龄为45岁的书籍。我已经尝试了如下内容(使用books文档根集)
findAll {it.author.age == 45}
findAll {it.author}.findAll {it.age == 45}
findAll {it.author}*.each {it.age == 45 }我仍然会找回所有有年龄项的记录。它可以是任意对象,可能没有author记录,等等。我希望返回根book对象。
我觉得我确实遗漏了一些很明显的东西,但文档似乎只涵盖了一个级别的键值。也许它不支持它?
谢谢!
发布于 2019-01-19 16:09:05
这就是了
books.findAll{it.author.age==45}它不是按照您的方式工作(findAll {it.author.age == 45}),因为您是从根开始工作的,而'it‘变量返回'books’对象,该对象没有'author‘字段。
https://stackoverflow.com/questions/45552998
复制相似问题