[英]GPath on nested objects
I'm not sure what I'm doing wrong here and I'm having a hell of a time with getting this to work properly. 我不确定自己在这里做错了什么,而且让它正常工作真是令人难过。 Using this JSON:
使用此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
}
]
}
I'm not able to extract the books where the authors age is 45, for example. 例如,我无法提取作者年龄为45岁的书籍。 I've tried things like the following (with the
books
document root set) 我已经尝试了以下操作(设置了
books
文档根目录)
findAll {it.author.age == 45}
findAll {it.author}.findAll {it.age == 45}
findAll {it.author}*.each {it.age == 45 }
I still get back all of the records that have an age item. 我仍然会取回所有带有年龄项目的记录。 It can be any arbitrary object, it might not have an
author
record, etc. And I want the root book
object returned. 它可以是任意对象,可能没有
author
记录等。我希望返回根book
对象。
I feel like there's something really obvious I'm missing, but the docs seem to only cover one level of key-values. 我觉得似乎确实缺少某些东西,但是文档似乎只涵盖了一个键值级别。 Maybe it doesn't support it?
也许它不支持它?
Thanks! 谢谢!
here is it 就这个
books.findAll{it.author.age==45}
It's not working your way (findAll {it.author.age == 45}) because you work from the root, and 'it' variable returns 'books' object, which has no field 'author'. 它无法按您的方式工作(findAll {it.author.age == 45}),因为您从根开始工作,并且“ it”变量返回“ books”对象,该对象没有字段“ author”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.