已解决
JsonPath 数据快速查找和提取工具
来自网友在路上 184884提问 提问时间:2023-11-04 14:08:12阅读次数: 84
最佳答案 问答题库848位专家为你答疑解惑
常用语法
过滤表达式
范围表达式
通配符表达式
操作符表达式
操作实战
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,"isbn": "0-553-21311-3"}],"bicycle": {"color": "red","price": 19.95}}
}
引入依赖
<dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.40</version></dependency>
示例
public static void main(String[] args) {String jsonStr = "{ \"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,\"isbn\": \"0-553-21311-3\"" +"}],\"bicycle\": {\"color\": \"red\",\"price\": 19.95}}}";JSONObject jsonObject = JSON.parseObject(jsonStr);System.out.println(jsonStr);System.out.println("book数目:"+ JSONPath.eval(jsonObject, "$.store.book.size()") );System.out.println("第一本书的title:"+JSONPath.eval(jsonObject,"$.store.book[0].title"));System.out.println("第一本书的category和author:"+JSONPath.eval(jsonObject,"$.store.book[0]['category','author']"));System.out.println("price>10的书:"+JSONPath.eval(jsonObject,"$.store.book[?(@.price > 10)]"));System.out.println("price>8的书的标题:"+JSONPath.eval(jsonObject,"$.store.book[?(@.price > 8)]"));System.out.println("price>7的书:"+JSONPath.eval(jsonObject,"$.store.book[?(@.price > 7)]"));System.out.println("price>7的书的标题:"+JSONPath.eval(jsonObject,"$.store.book[?(@.price > 7)].title"));System.out.println("书的标题为Sayings of the Century:"+JSONPath.eval(jsonObject,"$.store.book[?(@.title='Sayings of the Century')]"));System.out.println("bicycle的所有属性:"+JSONPath.eval(jsonObject,"$.store.bicycle.*"));System.out.println("bicycle:"+JSONPath.eval(jsonObject,"$.store.bicycle"));System.out.println("所有price:"+JSONPath.eval(jsonObject,"$.store.book[*].price"));}
查看全文
99%的人还看了
相似问题
- 〖大前端 - 基础入门三大核心之JS篇㊲〗- DOM改变元素节点的css样式、HTML属性
- CSS中常用的伪元素选择器
- XmlElement注解在Java的数组属性上,以产生多个相同的XML元素
- Web 自动化神器 TestCafe(二)—元素定位篇
- 代码随想录算法训练营第一天|数组理论基础,704. 二分查找,27. 移除元素
- 代码随想录算法训练营第五十九天 | LeetCode 739. 每日温度、496. 下一个更大元素 I
- JAXB:用XmlElement注解复杂类型的Java属性,来产生多层嵌套的xml元素
- Arcgis js Api日常天坑问题3——加载geojson图层,元素无属性
- 〖大前端 - 基础入门三大核心之JS篇㊳〗- DOM访问元素节点
- 力扣.82删除链表中的重复元素(java语言实现)
猜你感兴趣
版权申明
本文"JsonPath 数据快速查找和提取工具":http://eshow365.cn/6-31853-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: USB PD v1.0快速充电通信原理
- 下一篇: 6、QtCharts 悬浮曲线效果