教程:xPath和jsonPath使用

2018-08-16  本文已影响0人  jection

xPath是一种XML遍历的语法,可以从XML文档中提取特定的元素、属性、数据。
jsonPath是类似xPath的查询语法,可以从Json文档中提取特定的元素、属性、数据。

下面以一个json文本为案例,展示一下jsonPath和xPath的用法:

{ "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

  }

 }

}

例如

  1. 查找店铺store里所有书本的作者名字
  1. 查找书本标题为“Sword of Honour”的作者名字

更多查找案例如下:


图片.png
上一篇下一篇

猜你喜欢

热点阅读