我需要一些帮助才能找到使用jsonpath的兄弟姐妹。我想找到价格为0美元的所有地点。尝试过几个选项,比如$ .. price [?(@。lowest< = 0)],但它只选择匹配的节点。
感谢您的协助
[{
"fromDate": "2018-03-30",
"images": [{
"type": "LARGE",
"url": ""
}],
"price": {
"currencySymbol": "$",
"lowest": 0
},
"toDate": "2018-04-07",
"location": "Newyork, NY",
"priceSuffix": "per night",
"details": "2-Bedrooms"
},
{
"fromDate": "2018-03-30",
"images": [{
"type": "LARGE",
"url": ""
}],
"price": {
"currencySymbol": "$",
"lowest": 0
},
"toDate": "2018-04-07",
"location": "Atlanta, GA",
"priceSuffix": "per night",
"details": "2-Bedrooms"
}]
答案 0 :(得分:-1)
以下是基于您的数据的工作示例,您可以剪切并粘贴并尝试自己:
* def json =
"""
[{
"fromDate": "2018-03-30",
"images": [{
"type": "LARGE",
"url": ""
}],
"price": {
"currencySymbol": "$",
"lowest": 0
},
"toDate": "2018-04-07",
"location": "Newyork, NY",
"priceSuffix": "per night",
"details": "2-Bedrooms"
},
{
"fromDate": "2018-03-30",
"images": [{
"type": "LARGE",
"url": ""
}],
"price": {
"currencySymbol": "$",
"lowest": 1
},
"toDate": "2018-04-07",
"location": "Atlanta, GA",
"priceSuffix": "per night",
"details": "2-Bedrooms"
}]
"""
* def zero = $json[?(@.price.lowest==0)]
* match zero[0].location == 'Newyork, NY'
* def one = $json[?(@.price.lowest==1)]
* match one[0].location == 'Atlanta, GA'