程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

jsonpath_ Application of RW in Python

編輯:Python

1、 Application scenarios : Interface automation testing , There are parameter dependencies ,A The response parameters of the interface are used as B The request parameters of the interface request the interface , At this time, we need to start from A In the response data of B Get the required request parameters , At this time , It needs to be used jsonpath_rw

2、 Premise : install jsonpath_rw

pip install jsonpath_rw -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

3、 example :

from jsonpath_rw import jsonpath, parse
data={
"Code": 200,
"ErrorMessage": "",
"Data": {
"IsSuccess": true,
"Message": " Quantity updated successfully ",
"StackTrace": null,
"Data": {
"cartType": 0,
"CartId": "a47141fddd8848e1be5a281b25e613b8"
}
}
}
depend='Data.Data.CartId' # Write the data to be found according to the response data structure CartId
json_exe = parse(depend) # parse Used to parse... From a string json object
model = json_exe.find(response_data) # The return is list, But not the value we want
print([match.value for match in model][0])
# Return to the response parameter CartId Of a47141fddd8848e1be5a281b25e613b8

Official document address :GitHub - kennknowles/python-jsonpath-rw: A robust and significantly extended implementation of JSONPath for Python, with a clear AST for metaprogramming.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved