如何使用正则表达式提取器在 jmeter 中提取 json 响应数据? [英] how to extract json response data in jmeter using regular expression extractor?

查看:68
本文介绍了如何使用正则表达式提取器在 jmeter 中提取 json 响应数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想使用 jmeter 提取 json 响应数据,但无法这样做.
我得到了类似 {"authorizationToken":"abcdef"} 的东西.
我正在尝试获取 authorizationToken 但无法获取.

有人能帮我解决这个问题吗?

解决方案

authorizationToken 在响应中的外观是否唯一(是否只出现一次)?

如果是这样,您可以简单地使用 正则表达式提取器添加到返回 json 响应的 HTTP 请求,正则表达式如下:<代码><预>HTTP 请求正则表达式提取器参考名称:authToken正则表达式:"authorizationToken":"(.+?)"模板:$1$比赛编号:1

并将进一步提取的值引用为 ${authToken}.

<小时>

但是,如果您的情况更复杂,并且在 json 响应中有多个 authorizationToken 出现,并且您必须提取具体的可以使用的,例如BeanShell PostProcessor/BSF PostProcessor 添加到同一个 HTTP 请求以使用 beanshell 代码提取值 + json处理库.

如果不是 - 上面的第一个解决方案应该会有所帮助.

<小时>

更新:

目前处理 JSON 响应的最舒适方式似乎是自定义 JSON utils 用于 jmeter(JSON 路径断言、JSON 路径提取器、JSON 格式化程序),它们也是 Jmeter 插件.

在这种特殊情况下,您可以使用 JSON 路径提取器.

I am just trying to extract json response data using jmeter but not able to do so.
I am getting something like {"authorizationToken":"abcdef"}.
I am trying to get authorizationToken but not able to get this.

Can anyone help me getting this working?

解决方案

Is authorizationToken appearance unique in response (does it appear only once)?

If it does you may simply use Regular Expression Extractor added to the HTTP Request which returns json response, with regex like following:

HTTP Request
    Regular Expression Extractor
    Reference Name: authToken
    Regular Expression: "authorizationToken":"(.+?)"
    Template: $1$
    Match No.: 1

and refer further extracted value as ${authToken}.


But if your case is more complicated and there several appearances of authorizationToken in json response and you have to extract concrete one you may use e.g. BeanShell PostProcessor / BSF PostProcessor added to the same HTTP Request to extract value with beanshell code + json processing library.

If not - the first solution above should help.


UPDATE:

At the moment the most comfortable way to process JSON responses seems to be custom JSON utils for jmeter (JSON Path Assertion, JSON Path Extractor, JSON Formatter) which are also part of Jmeter Plugins.

In this particular case you can use JSON Path Extractor.

这篇关于如何使用正则表达式提取器在 jmeter 中提取 json 响应数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆