在 JMeter 中捕获值的正则表达式

问题描述 投票:0回答:1

在Jmeter中,想要从下面的json响应代码中捕获POD的id。尝试 $..result[*].id 并显示所有 ID,包括 Value1、Value2 中的一次。但我的要求只是捕获PODID,以便可以在下一个请求中传递它。 是否可以将 PODID 保存在数组中并在下一个请求中发送它们?

{
    "result": [
        {
            "Value1": {
                "name": "Random1145843",
                "id": "32f338ffce"
            },
            "parent": null,
            "capabilities": null,
            "configuration": null,
            "timeZone": "America\/New_York",
            
            "Value2": {
                "name": "Random1137530",
                "id": "0940c7a8d7"
            },
            "ready": "ready",
            "organization": {
                "name": "Randome42711",
                "id": "da54c68830"
            },
            "name": "PodId_50631",
            "host": null,
            "id": "PODID_50631",
            "state": {
                 "mil": "clear",
                "diagnostic": "clear",
                            },
            "status": {
                "estimated_weight
                    "value": {
                        "uom": "KG,
                        "value": 500.0
                    }
                   
                },
               
           {
            "Value1": {
                "name": "Random1145443",
                "id": "32f3385fce"
            },
            "parent": null,
            "capabilities": null,
            "configuration": null,
            "timeZone": "America\/New_York",
            
            "Value2": {
                "name": "Random1137530",
                "id": "0940c758d7"
            },
            "ready": "ready",
            "organization": {
                "name": "Randome42755",
                "id": "da54c65630"
            },
            "name": "PodId_506356,
            "host": null,
            "id": "PODID_506356",
            "state": {
                 "mil": "clear",
                "diagnostic": "clear",
                            },
            "status": {
                "estimated_weight
                    "value": {
                        "uom": "KG,
                        "value": 500.0
                    }
                   
                },
                     {
            "Value1": {
                "name": "Random1145653",
                "id": "32f338f564"
            },
            "parent": null,
            "capabilities": null,
            "configuration": null,
            "timeZone": "America\/New_York",
            
            "Value2": {
                "name": "Random1135630",
                "id": "0940c734
            },
            "ready": "ready",
            "organization": {
                "name": "Randome42756
                "id": "da54c68830"
            },
            "name": "PodId_34556,
            "host": null,
            "id": "PODID_34556",
            "state": {
                 "mil": "clear",
                "diagnostic": "clear",
                            },
            "status": {
                "estimated_weight
                    "value": {
                        "uom": "KG,
                        "value": 500.0
                    }
                 
]
}
json jmeter performance-testing
1个回答
0
投票

您正在使用

..
operator,这意味着“深度扫描”,因此它将返回所有
id
属性值,无论它们位于何处。

您需要将

id
属性的提取限制为仅
result
JSON 数组 的直接子级。比如:

result.*.id

更多信息:JMeter 的 JSON 路径提取器插件 - 高级使用场景

© www.soinside.com 2019 - 2024. All rights reserved.