JsonPath表达式使用正则表达式进行过滤
发布时间:2020-12-14 05:59:53 所属栏目:百科 来源:网络整理
导读:我们正在使用一个使用jayway库来评估 JSONpath表达式的工具. Javascript似乎不适用它.在这种情况下,如何在JSONPath中使用正则表达式.例如,在下面的示例中,我想过滤其标题中包含“Sword”一词的所有书名: { "store": { "book": [ { "category": "reference",
我们正在使用一个使用jayway库来评估
JSONpath表达式的工具.
Javascript似乎不适用它.在这种情况下,如何在JSONPath中使用正则表达式.例如,在下面的示例中,我想过滤其标题中包含“Sword”一词的所有书名:
{ "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 },"author": "Herman Melville","title": "Moby Dick","isbn": "0-553-21311-3","price": 8.99 },"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 } 解决方法
Jayway implementation使用Ruby正则表达式运算符:
$.store.book[?(@.title =~ /^.*Sword.*$/)] 忽略大小写: $.store.book[?(@.title =~ /^.*sword.*$/i)] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |