JSON提取器可以很方便的让你从JSON响应格式中提取数据。
1)Name:JSON提取器的名称。
2)Apply to:应用范围,有些采样器还嵌套子采样器,可以在此处设置JSON提取器是作用与主采样器和子采样器还是仅仅主采样器等。
3)Names of created variables:分号分割的变量的名称。
4)JSON Path expressions:JSON Path表达式。
JSON Path | 描述 |
$ | 表示根元素 |
@ | 表示当前节点 |
. | 表示子节点 |
.. | 选择所有符合条件的节点 |
* | 所有节点 |
[] | 迭代器标识,如数组下标 |
[,] | 支持迭代器中多选 |
[start:end:step] | 数组切片 |
?() | 支持过滤 |
() | 支持表达式计算 |
1 { "store": { 2 ????"book": [ ?3 ??????{ "category": "reference", 4 ????????"author": "Nigel Rees", 5 ????????"title": "Sayings of the Century", 6 ????????"price": 8.95 7 ??????}, 8 ??????{ "category": "fiction", 9 ????????"author": "Evelyn Waugh",10 ????????"title": "Sword of Honour",11 ????????"price": 12.9912 ??????},13 ??????{ "category": "fiction",14 ????????"author": "Herman Melville",15 ????????"title": "Moby Dick",16 ????????"isbn": "0-553-21311-3",17 ????????"price": 8.9918 ??????},19 ??????{ "category": "fiction",20 ????????"author": "J. R. R. Tolkien",21 ????????"title": "The Lord of the Rings",22 ????????"isbn": "0-395-19395-8",23 ????????"price": 22.9924 ??????}25 ????],26 ????"bicycle": {27 ??????"color": "red",28 ??????"price": 19.9529 ????}30 ??}31 }
JSONPath | 结果 |
$.store.book[*].author | 书店所有书的作者 |
$..author | 所有的作者 |
$.store.* | store的所有的元素,包括book和bicyle |
$.store..price | store所有东西的price |
$..book[2] | 第三本书 |
$..book[(@.legnth-1)] | 最后一本书 |
$..book[0,1] | 前面的两本书 |
$..book[:2] | 前面的两本书 |
$..book[?(@.isbn)] | 过滤出所有的包含isbn的书 |
$..book[?(@.price<10)] | 过滤出价格低于10的书 |
$..* | 所有元素 |
5)匹配数字,0表示随意,-1代表所有,后续在引用时使用变量名_N取第N个值。
6)Compute concatenation var:如果找到的值很多,将把他们用‘,‘分割并保存在变量名_ALL的变量中。
7)Default Value:如果匹配不到值时,使用这里设置的默认值。
后置处理器----JSON提取器
原文地址:https://www.cnblogs.com/zhuzhaoli/p/10269534.html