Java三方库记录
来源:互联网 发布:mac下载os x yosemite 编辑:程序博客网 时间:2024/05/01 13:44
Java实现SSH
jsch
Ganymed SSH-2 for Java是一个纯Java实现的SHH2库
Java处理sql语句
jsqlparser
http://blog.csdn.net/isea533/article/details/40375183
Java处理html
jsoup
Java处理json串
Jayway JsonPath
https://github.com/json-path/JsonPath
<dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.3.0</version></dependency>
JsonPath表达式语法
JsonPath表达式形如:$.store.book[0].title 或 $['store']['book'][0]['title']$
The root element to query. This starts all path expressions.@
The current node being processed by a filter predicate.*
Wildcard. Available anywhere a name or numeric are required...
Deep scan. Available anywhere a name is required..<name>
Dot-notated child['<name>' (, '<name>')]
Bracket-notated child or children[<number> (, <number>)]
Array index or indexes[start:end]
Array slice operator[?(<expression>)]
Filter expression. Expression must evaluate to a boolean value.JsonPath表达式用法示例
{ "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 } }, "expensive": 10}
结合Java使用
用法一:使用static JsonPath.read方法直接去读json string
String json = "...";List<String> authors = JsonPath.read(json, "$.store.book[*].author");用法二:将json string 转换为Object再使用
String json = "...";Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);String author0 = JsonPath.read(document, "$.store.book[0].author");String author1 = JsonPath.read(document, "$.store.book[1].author");两种用法的区别:
当对同一个json串多次读取时,使用第二种方法,因为第一种方法每次都是构建一个object对象,影响效率。
用法三:
String json = "...";ReadContext ctx = JsonPath.parse(json);List<String> authorsOfBooksWithISBN = ctx.read("$.store.book[?(@.isbn)].author");List<Map<String, Object>> expensiveBooks = JsonPath .using(configuration) .parse(json) .read("$.store.book[?(@.price > 10)]", List.class);
JsonPath结合数据类型构造数据
//Will throw an java.lang.ClassCastException List<String> list = JsonPath.parse(json).read("$.store.book[0].author")//Works fineString author = JsonPath.parse(json).read("$.store.book[0].author")String json = "{\"date_as_long\" : 1411455611975}";Date date = JsonPath.parse(json).read("$['date_as_long']", Date.class);Book book = JsonPath.parse(json).read("$.store.book[0]", Book.class);TypeRef<List<String>> typeRef = new TypeRef<List<String>>() {};List<String> titles = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[*].title", typeRef);
其他用法
与或非:
[?(@.price < 10 && @.category == 'fiction')] , [?(@.category == 'reference' || @.price > 10)][?(!(@.price < 10 && @.category == 'fiction'))]过滤器:
import static com.jayway.jsonpath.JsonPath.parse;import static com.jayway.jsonpath.Criteria.where;import static com.jayway.jsonpath.Filter.filter;......Filter cheapFictionFilter = filter( where("category").is("fiction").and("price").lte(10D));List<Map<String, Object>> books = parse(json).read("$.store.book[?]", cheapFictionFilter); Filter fooOrBar = filter( where("foo").exists(true)).or(where("bar").exists(true)); Filter fooAndBar = filter( where("foo").exists(true)).and(where("bar").exists(true));
阅读全文
0 0
- Java三方库记录
- java记录
- java记录
- Java记录
- Java记录
- java记录
- Java记录
- java学习记录20061008
- Java 课堂记录 02
- JAVA工作面试记录
- java.lang.NoClassDefFoundError记录
- ITPUB JAVA 专题记录
- java学习记录
- JAVA日志记录,LOG4J
- 记录一些java代码
- java学习记录
- java API学习记录
- java错误记录
- git 常用命令
- 浅析Java中equals()方法和hashCode方法
- Codeforces-242C-King's Path(bfs)
- virtualbox centos7/ubuntu 网络配置
- ProjectForge研究第二天:工程及模块
- Java三方库记录
- 编程检验ASCII码值与字符对应关系 P11
- 第九章0.1解读
- Codeforces Round #441 (Div.2)
- 算数运算符和算术表达式
- Cygwin 和MinGW 的区别与联系是怎样的?
- Codeforces Round #149 (Div. 2) (bfs+STL)
- Fault Injection——持续更新
- 游戏‘微信打飞机 第一课