【发布时间】:2017-09-15 09:15:49
【问题描述】:
我有这种结构的 JSON:
{
"stores": {
"store1_id": {
"books": {
"book1_ISBN": {
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": "8.95"
},
"book2_ISBN": {
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": "12.99"
}
}
},
"store2_id": {
"books": {
"book3_ISBN": {
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": "22.99"
}
}
}
}
}
然后我用Jayway JsonPath 解析它。我尝试使用这样的表达方式获取所有小说类别的书籍:
$[?(@.stores.*.books)].stores.*.books[?(@.*.category=="reference")]
但我得到空结果,尽管根据同等的运营商文档,我希望我会收到“世纪语录”书节点:
"book1_ISBN": {
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": "8.95"
}
有趣的是,当我使用这个不带等号运算符的表达式时:
$[?(@.stores.*.books)].stores.*.books[?(@.*.category)]
我得到了所有三本书的结果。为什么我的等号表达式不起作用?
【问题讨论】: