作者:乐橙味_367 | 来源:互联网 | 2023-05-25 14:51
使用ashphy json路径评估器和以下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
}
}
}
我想写一个过滤类别的查询,例如"小说",然后只返回第一个元素.我似乎无法弄明白.
例如,$..book[?(@.category == "fiction")]
将返回3本书的数组,但我只想要第一本书:
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
可以吗?显而易见的事情似乎是在最后添加"[0]",但它不起作用.