JSONPath筛选fiction/fantasy分类图书遇语法问题,求解决方法
JSONPath多类别筛选解决方案
问题原因
- 你使用的JSONPath工具实现的是Stefan Goessner原始JSONPath规范,该规范不支持
in操作符,因此[?(@.category in ['fiction','fantasy'])]这类写法无法生效。 - 你尝试的表达式
$.store.book.[?(@.category in ['fiction','fantasy'])]中,book后面多了一个多余的.,属于语法错误,会导致表达式解析失败。
可行表达式写法
直接用逻辑或(||)拼接多个相等判断,同时去掉book后的多余点:
$.store.book[?(@.category == 'fiction' || @.category == 'fantasy')]
筛选结果
使用该表达式处理你提供的书店数据,会返回以下两本符合条件的图书:
[ {"category": "fiction","author": "Evelyn Waugh","title": "Sword of Honour","price": 12.99}, {"category": "fantasy","author": "J. R. R. Tolkien","title": "The Lord of the Rings","isbn": "0-395-19395-8","price": 22.99} ]
内容的提问来源于stack exchange,提问作者Christian Schlaefcke
相关产品推荐
相关产品推荐

