Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JSON parsing how to use the artifact JsonPath

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

JSON parsing artifact JsonPath how to use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

A brief introduction to grammar

JsonPath describes $root node @ current node. Or [] child node.. Select all eligible nodes * all nodes are marked with [] iterator, such as array subscript [,] supports multiple selection [start:end:step] array slicing operator in iterator? () supports filtering operation () supports expression evaluation

JSON value:

Guide package: import com.jayway.jsonpath.JsonPath

Parse the code:

/ output the author value of book [0] String author = JsonPath.read (json, "$.store.book [0] .author"); System.out.println ("author\ t" + author); / / output the values of all author, iterating with Iterator List authors = JsonPath.read (json, "$store.book [*] .author"); System.out.println ("authors\ t" + authors) / output bookList books = 'reference' bookList books = JsonPath.read (json, "$store.book [? (@ .category = =' reference')]") in book [*]; System.out.println ("books\ t" + books); / / output book of category = = 'reference' or List books2 = JsonPath.read in book [*] (json, "$store.book [? (@ .category =' reference' | @ .price > 10)"); System.out.println ("books2\ t" + books2) / output authorList books1 = JsonPath.read of book of category = 'reference' in book [*] (json, "$store.book [? (@ .category = =' reference')] .author"); System.out.println ("books1\ t" + books1); / / output bookList b1 of price > 10 in book [*] = JsonPath.read (json, "$store.book [? (@ .price > 10)]); System.out.println (" b1 "+ b1) / / output bookList b2 = JsonPath.read (json, "$store.book [? (@ .isbn)]) containing isbn elements in book [*]; System.out.println (" b2 "+ b2); / / output the values of all price in the json List prices = JsonPath.read (json," $... prices "); System.out.println (" prices "+ prices); / / output the values of all title in the json List title = JsonPath.read (json," $.. title ") System.out.println ("title" + title); / / output the value of book0, 1 in the json List book01 = JsonPath.read (json, "$.. book [0Magne1]"); System.out.println ("book01" + book01); / * / output the value of book0, 1 in the json List book012 = JsonPath.read (json, "$.. book [- 2:]"); System.out.println ("book012" + book012) * / / you can edit a path in advance and use it many times JsonPath path = JsonPath.compile ("$.store.book [*]"); List b3 = path.read (json); System.out.println ("path\ t" + path+ "\ n" + b3). Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report