meter json和正在提取及断言
一、提取所需要断言的内容:
响应数据如下:加入需要提取userid为10477的值
{
"pub": {
"status": 0,
"userId": "10477",
"apiVersion": "3.9.4.3004",
"subPline": "2",
"clientAgent": "svnVer_1907021457",
"channelCode": "AOT1001757",
"appCode": "f002",
"model": "ALP-AL00",
"imsi": "dz_1562222817068",
"imei": "dz_1562222817068",
"screen": "720x1206",
"os": "android28",
"pname": "com.ishugui12343",
"apn": "wifi",
"ip": "192.168.103.113",
"province": "北京市",
"city": "北京"
},
"pri": {
"result": "0",
"tips": "验证码错误",
"account": [
{
"coverWap": "",
"appid": "PHONE_NUM_VERIFY",
"nickname": "",
"id": "",
"key": "PHONE_NUM_VERIFY"
}
]
}
}
1、sample添加-后置处理器-添加JSON Extracror(这里面需要稍微学习下json path espressions的语法了)--得到id的值90
自己看这个网址学习吧:http://goessner.net/articles/JsonPath/
2、也可以使用正则表达式提取
"userId":(.+?),
3.关联
下一个请求,使用提取的参数: ${userid_1} 或{userid_2}
二、断言提取出来的值
sample-断言-添加json assert
三、json path espressions的语法学习
$:跟对象\元素
@:当前对象\元素
?():应用过滤器(脚本)表达式
还是自己练习吧。。。。
{ "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
}
}
}
$.store.book[*].author:商店所有书籍的作者(四个作者)
$..author :所有作者
$.store.* :商店所有的东西,包括book和bicycle
$.store..price :所有东西的价格
$..book[2] :第三本书
$..book[0,1] /$..book[:2] :前两本书
$..book[?(@.isbn)] :用isbn编号过滤所有书籍
$..book[?(@.price<10)] :过滤所有比10更便宜的书
$..* :XML文档中的所有元素
规则:
$ 根节点
@ 现行节点
. 子节点
..不管位置,选择所有符合条件的
* 匹配所有元素节点
[,] 支持迭代器中做多选
?() 支持过滤操作
[] 迭代器的标示,子元素操作符
() 支持表达式计算