JsonPath 使用
Map<String, String> map ----> $.store.bicycle
String str = $.store.other
List<Map<String, String>> list = $.store.book
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
Map<String, String> entries = JsonPath.read(str, "$");
JSONPATH Parse JSON array file:
If the object is:
[
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4],
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
]
Then "$[0]" will return:
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]
And "$[1]" will return:
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
You can do it two levels deep as well. "$[0][4]" will return:
205
You can also extract the elements of the array into a list with "$[*]", which will return a list of 2 elements. The first being:
[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4]
and the second being:
[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2]
{
"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
} "other":"[{\"filterable\":\"true\",\"dataIndex\":\"DateValue\",\"dataType\":\"date\",\"isInStandardView\":\"true\",\"sortAsConverterFormat\":\"yyyyMMdd\",\"id\":\"DateValue\",\"sortable\":\"true\",\"isVisible\":\"true\"},{\"filterable\":\"true\",\"dataIndex\":\"DateType\",\"dataType\":\"string\",\"isInStandardView\":\"true\",\"sortAsConverterFormat\":null,\"id\":\"DateType\",\"sortable\":\"true\",\"isVisible\":\"true\"}]"
},
"expensive": 10
}
{ "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
}
}
}
private static void jsonPathTest() {
JSONObject json = jsonTest();//调用自定义的jsonTest()方法获得json对象,生成上面的json
//输出book[0]的author值
String author = JsonPath.read(json, "$.store.book[0].author");
//输出全部author的值,使用Iterator迭代
List<String> authors = JsonPath.read(json, "$.store.book[*].author");
//输出book[*]中category == 'reference'的book
List<Object> books = JsonPath.read(json, "$.store.book[?(@.category == 'reference')]");
//输出book[*]中price>10的book
List<Object> books = JsonPath.read(json, "$.store.book[?(@.price>10)]");
//输出book[*]中含有isbn元素的book
List<Object> books = JsonPath.read(json, "$.store.book[?(@.isbn)]");
//输出该json中所有price的值
List<Double> prices = JsonPath.read(json, "$..price");
//可以提前编辑一个路径,并多次使用它
JsonPath path = JsonPath.compile("$.store.book[*]");
List<Object> books = path.read(json);
}
JsonPath 使用的更多相关文章
- restassured - JsonPath
https://github.com/rest-assured/rest-assured/blob/master/json-path/src/test/java/io/restassured/path ...
- jsonpath
1. java 类库 jayway/JsonPath maven 使用方法 <dependency> <groupId>com.jayway.jsonpath</grou ...
- 使用jsonpath解析json内容
JsonPath提供的json解析非常强大,它提供了类似正则表达式的语法,基本上可以满足所有你想要获得的json内容.下面我把官网介绍的每个表达式用代码实现,可以更直观的知道该怎么用它. 一.首先需要 ...
- 好用的json-path
$.store.book[?(@.price < 10)].title Here is a complete overview and a side by side comparison of ...
- JsonPath详解
JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPat ...
- 一.HttpClient、JsonPath、JsonObject运用
HttpClient详细应用请参考官方api文档:http://hc.apache.org/httpcomponents-client-4.5.x/httpclient/apidocs/index.h ...
- jsonpath读取json数据格式公用方法!!!
import java.util.LinkedHashMap; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Pred ...
- Python爬虫(十六)_JSON模块与JsonPath
本篇将介绍使用,更多内容请参考:Python学习指南 数据提取之JSON与JsonPATH JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它是的人们很容易 ...
- JSONPath使用
JSONPath是fastjson在1.2.0之后支持的.JSONPath是一个很强大的功能.关于JSONPath的介绍请查看官方文档 JSONPath. 官方文档上给出了详细的说明以及使用.但是官方 ...
- Python_实现json数据的jsonPath(精简版)定位及增删改操作
基于python实现json数据的jsonPath(精简版)定位及增删改操作 by:授客 QQ:1033553122 实践环境 win7 64 Python 3.4.0 代码 #-*- encod ...
随机推荐
- vs2017如何设置类或函数前不显示引用的数量
这几天,从vs2013换成vs2017,17版本增加了一个类或函数前提示引用的数量,这个感觉很别扭,如何取消显示这个呢? 问题如下: 取消显示这个引用的步骤: 找到菜单栏: 工具 ---> 选项 ...
- caffe matlab matcaffe 加载输入网络net时报错
http://blog.csdn.net/xiaojiajia007/article/details/72850247
- apache配置,apache直接打开文件而不下载问题
apache什么用,如何下载的上面就不说了,apache的配置是一个非常复杂的工作,下面介绍最基本的apache配置吧,再介绍配置文件管理系统. 安装过后需修改配置: 修改httpd.conf配置文件 ...
- JAVA概率实现--一篇最常见、最通用解决方案
日常场景:某活动抽奖,控制各等奖的出现概率 比如控制A(中奖率):20%:B(获得优惠券率):30%:C(谢谢参与率):50% 下面以封装好在main()函数里,上代码(记得导入相应的包): publ ...
- python与sqlserver接口包pymssql
包下载地址(对应着自己的电脑和Python的版本下载即可,我电脑是win32,Python是3.6的) https://pypi.python.org/pypi/pymssql/ 下载后我放到了d盘中 ...
- Problem E: 类的初体验(V)
Description 定义一个类Data,只有一个int类型的属性和如下方法: 1. 缺省构造函数,将属性初始化为0,并输出"Data's default constructor.&q ...
- Linux每天一个命令:nc/ncat
nmap-ncat.x86_64版nc/ncat nc/ncat所做的就是在两台电脑之间建立链接并返回两个数据流,在这之后所能做的事就看你的想像力了.你能建立一个服务器,传输文件,与朋友聊天,传输流媒 ...
- noj最长公共子序列
1041.最长公共子序列 时限:1000ms 内存限制:200000K 总时限:3000ms 描述 一个给定序列的子序列是在该序列中删去若干元素后得到的序列.确切地说,若给定序列X=<x1, ...
- 虚拟机U盘挂载
虚拟机中U盘挂载 一.连接U盘 虚拟机中 虚拟机→可移动设备→Syntek USB......(U盘的名称)→连接: 二.查看U盘的UUID “lsblk -f”: UUID为 35E6-9 ...
- linux ipv6开启的配置文件
1./etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0TYPE=EthernetUUID=9d1d6e2a-cfc5-4e60-8f28-b77 ...