why957

1 jsonPath数据格式

pip安装: pip install jsonpath
用来解析json格式的字符串,类似于xpath

(1) json对象的转换
json.loads()
json.dumps()
json.load()
json.dump()

#直接读取json对象
json_obj = json.load(open('books.json','r',encoding='utf-8'))
print(json_obj) 

#先读取json字符串,再转json对象
with open('books.json','r',encoding='utf-8') as fp:
    json_str = fp.read()
json_obj = json.loads(json_str,encoding='utf-8')
print(json_obj)
(2) XPath与jsonPath格式对比
XPath JSONPath Description
/ $ 表示根元素
. @ 当前元素
/ . or [] 子元素
.. n/a 父元素
// .. 递归下降,JSONPath是从E4X借鉴的。
* * 通配符,表示所有的元素
@ n/a 属性访问字符
[] [] 子元素操作符
| [,] 连接操作符在XPath 结果合并其它结点集合。JSONP允许name或者数组索引。
n/a [start

相关文章:

  • 2021-07-29
  • 2022-01-15
  • 2021-08-14
  • 2021-05-23
  • 2021-11-01
  • 2021-04-22
  • 2021-04-22
  • 2021-10-12
猜你喜欢
  • 2021-11-05
  • 2021-11-11
  • 2021-05-31
  • 2022-12-23
  • 2021-12-13
  • 2021-10-26
  • 2021-04-11
相关资源
相似解决方案