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 ...
随机推荐
- C# 关键字this用法
1.this代表当前类的实例对象 public class Test { public string Name{get;set;} public void TestChange(string strN ...
- python----集合用法总结
集合也是一种数据类型,一个类似列表东西,它的特点是无序的,不重复的,也就是说集合中是没有重复的数据集合的作用:1.它可以把一个列表中重复的数据去掉,而不需要你再写判断2.可以做关系测试,比如说有两个班 ...
- jQuery抽奖插件 jQueryRotate
实现代码 网页中引用 <script type="text/javascript" src="js/jquery.min.js"></scri ...
- python -- 字典 集合
1.字典 定义:字典是以 key :value 的形式来保存数据,用{} 来表示,存储的是 key : value 查找效率比较高(注:字典存储数据时,用的是hash值 ...
- vue 自定义组件使用v-model
<input v-model="something"> v-model指令其实是下面的语法糖包装而成: <input :value="something ...
- xss之cookie窃取
一.窃取cookie有什么用? cookie相当于一个身份证 有了管理员的cookie我们不需要帐号密码就可以登陆 二.反射型xss有存贮型xss什么区别? 反射 xss 和服务器没有交互 只能用一 ...
- Oracle 11g 静默安装脚本
#!/bin/bash####安装Oracle所需依赖包function install_yum(){ yum -y install $1} i="perl-Data-Dumper lvm ...
- Linux内核分析--理解进程调度时机、跟踪分析进程调度和进程切换的过程
ID:fuchen1994 姓名:江军 作业要求: 理解Linux系统中进程调度的时机,可以在内核代码中搜索schedule()函数,看都是哪里调用了schedule(),判断我们课程内容中的总结是否 ...
- FPGA型号解读
- eclipse工具类及插件(Eclipse超好用的插件推荐)
https://blog.csdn.net/ghostxbh/article/details/80054948