gpt4 book ai didi

java - JSONpath 中的 && 运算符 ()

转载 作者:行者123 更新时间:2023-12-01 18:01:40 25 4
gpt4 key购买 nike

下面是来自 tutorial 的示例 json

{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}

我正在尝试检查具有以下条件的对象

$..[?(@.price == 12.99 && @.title == 'Moby Dick')]

应该如下所示找回我。但是,它只显示[]。

{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},

是否有任何关于查询中出现错误的指示?

最佳答案

您应该使用 || 而不是 &&,因为您想要具有任一价格的对象(而不是两者,这是不可能的):

$..[?(@.price == 12.99 || @.price == 8.99)]

关于java - JSONpath 中的 && 运算符 (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40477576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com