Jmeter Xpath提取器JSON [英] Jmeter Xpath Extractor JSON

查看:201
本文介绍了Jmeter Xpath提取器JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JMETER XPATH Extractor从以下JSON中提取参数roomNo:

I'm trying to extract the parameter roomNo from the following JSON with JMETER XPATH Extractor:

*/
{   
"categoryCode": ["I4"],
"Response": {
    "class": "example",
    "availables": {
        "available": [
            {
                "Desc": " Middle",
                "roomNo": "5049"
            },
            {
                "Desc": " Middle",
                "roomNo": "5062"
            }
            ],
        "class": "test"
    },
    "advisoryInfo": null
},
"storeId": "10251"
}
*/

我使用以下表达式失败:

i use the following expression with no success:

/Response/availables/available[0]/roomNo

表达错误吗?

更新:

我尝试使用JSON PATH EXTRATCTOR插件.我尝试了以下查询,但均未成功:

i'm try to use the plugins JSON PATH EXTRATCTOR. i tryied the following queries with no success:

$...available[0]

$.Response.availables.available..roomNo[0]

$.Response.availables.available[0].roomNo


UPDATE1:


UPDATE1:

更多考虑:我收到的ajax响应以*/开头,这是否可能给JSON EXTRACTOR带来麻烦?我通过查看结果树

one more consideration: the ajax response I recieve starts with */, is it possible this creates troubles with JSON EXTRACTOR? i see the response through view Results Tree

UPDATE2: 我尝试以下方法:

UPDATE2: i try the following approach:

ajax请求,然后是bash提取器,然后是json提取器,但仍然无法正常工作

ajax request followed by bash extractor, followed by json extractor but it is still not working

我按照以下建议操作了 字符串临时=新字符串(prev.getResponseDataAsString()); prev.setResponseData(temp.replaceAll("\ */",").getBytes());

in bash extractor i did as suggested using the following strings String temp = new String(prev.getResponseDataAsString()); prev.setResponseData(temp.replaceAll("\*/","").getBytes());

更多问题:

是否可以看到bash提取器的结果? 我应该在json提取程序之前声明它应该使用temp变量吗?怎么样?

推荐答案

恐怕XPath Extractor不允许您解析JSON.

I'm afraid XPath Extractor won't let you parsing JSON.

您需要 JSONPath提取器可通过

You'll need JSONPath Extractor available via JMeter Plugins (you need Extras with Libs Set).

在您的情况下,相关的JSONPath查询将如下所示:

In your case relevant JSONPath query will look like:

$.Response.availables.available..roomNo[0]

查看在JMeter中使用XPath提取器指南(向下滚动解析JSON )以获取更多信息以及XPath到JSONPath映射表.

Check out Using the XPath Extractor in JMeter guide (scroll down to Parsing JSON) for more information and XPath to JSONPath mappings table.

希望这会有所帮助.

UPD.您可以使用Beanshell Post Processor摆脱*/位,在这种情况下,JSONPath应该可以正常工作. Beanshell PostProcessor代码:

UPD. You can use Beanshell Post Processor to get rid of your */ bits, in that case JSONPath should work fine. Beanshell PostProcessor code:

String temp = new String(prev.getResponseDataAsString());
prev.setResponseData(temp.replaceAll("\\*/","").getBytes());

确保Beanshell Post Processor在JSONPath Extractor之前 .

Make sure that Beanshell Post Processor goes before JSONPath Extractor.

这篇关于Jmeter Xpath提取器JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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