JSON 信息抽取類庫:JsonPath
JsonPath 對于 JSON 來說相當于 XPATH 對于 XML。這是一個簡單的從文檔中抽取指定信息的工具,提供多種語言實現版本,包括:Javascript, Java, Python 和 PHP。
給定以下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
}
}
}讀取
所有作者:
List<String> authors = JsonPath.read(json, "$.store.book[*].author");
Author of first book in store:
String author = JsonPath.read(json, "$.store.book[1].author");
所有分類="reference"的書籍
List<Object> books = JsonPath.read(json, "$.store.book[?(@.category == 'reference')]");
List<Object> books = JsonPath.read(json, "$.store.book[?]", filter(where("category").is("reference")));
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!