我试图找到一个jsonpath表达式,该表达式仅在json数组同时包含类别“ fiction”和“ reference”时才返回值,而当json仅包含类别之一时不返回任何值。
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century"
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick"
},
{
"category": "fiction",
"author": "J.R.R. Tolkien",
"title": "The Lord of the Rings"
}
]
}
}
当json包含两个类别时,以下表达式均有效,但是即使json仅包含两个类别之一,它仍会返回结果。
$..book[?(@.category == 'fiction' || @.category == 'reference')]
如果我尝试使用&&代替|| -我遇到了表达错误。
$..book[?(@.category == 'fiction' && @.category == 'reference')]