regex - 使用正则表达式 Jmeter 从 Json 获取密钥
问题描述
我正在使用正则表达式,并试图从这个身体中获取 id。但只有成员列表中的 id,而不是已验证密钥中的 id。:) 澄清一下,我在 JMeter 中使用正则表达式提取器
{
"id": "9c40ffca-0f1a-4f93-b068-1f6332707d02", //<--not this
"me": {
"id": "38a2b866-c8a9-424f-a5d4-93b379f080ce", //<--not this
"isMe": true,
"user": {
"verified": {
"id": "257e30f4-d001-47b3-9e7f-5772e591970b" //<--not this
}
}
},
"members": [
{
"id": "88a2b866-c8a9-424f-a5d4-93b379f780ce", //<--this
"isMe": true,
"user": {
"verified": {
"id": "223e30f4-d001-47b3-9e7f-5772e781970b" //<--not this
}
}
},
{
"id": "53cdc218-4784-4e55-a784-72e6a3ffa9bc", //<--this
"isMe": false,
"user": {
"unverified": {
"verification": "XYZ"
}
}
}
]
}
目前我有这个正则表达式:
("id": )("[\w-]+")
但正如您在此处看到的,它返回每个 guid
关于如何继续的任何想法?
提前致谢。
解决方案
由于输入数据类型为 JSON,建议使用JMeter 的 JSON Path Extractor Plugin。
添加后,使用
$.members[*].id
JSON 路径表达式,用于匹配文档中作为顶部节点id
的每个值的所有值。members
如果您可能已经嵌套memebers
,则可以使用它们全部
$..members[*].id
你可以在https://jsonpath.com/测试这些表达式,看一个测试:
推荐阅读
- vue.js - 如何在使用 v-for 时更新文本输入值
- javascript - 如何访问嵌套数组中的特定值
- firebase - 错误:Firebase:没有创建 Firebase 应用“[DEFAULT]”
- android - 关于在我的第一个 android 应用程序中使用 Selenium
- python - 从 x**2 的 MATLAB 运算符错误中调用 Python
- python - Scipy odeint 在负时间值处评估
- regex - 如何删除记事本++中第一个冒号之前的所有内容?
- ios - Google NearBy API 使用和定价
- javascript - 如何通过 Safari 中的 FontFace 界面加载文件名以数字开头的字体
- deep-learning - BERT 输出不确定