Jmeter-JSON提取器

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

我正在尝试创建一个json表达式路径,当使用{" id ":" 00000000000000000000000004640254 "}进行引用时,该路径会返回ID。我尝试过

$.[?(@.Relationship[?(@.Ref.id=='00000000000000000000000004640254')])].id

但它不返回数据

Json消息是

[
    {
        "id": "234567890234567890",
        "Relationship": [
            {
                "type": "Indirect",
                "Ref": {"id": "00000000000000000000000004640253_01"}
            },
            {
                "type": "Direct",
                "Ref": {"id": "00000000000000000000000004640254"}
            }
        ],
        "Specification": {"id": "Gold123AS"}
    },
    {
        "id": "234567890234567891",
        "Relationship": [
            {
                "type": "Indirect",
                "Ref": {"id": "00000000000000000000000004640253_02"}
            },
            {
                "type": "Direct",
                "Ref": {"id": "00000000000000000000000004640253"}
            }
        ],
        "Specification": {"id": "Gold123AS"}
    }
]

如果有人可以帮助我,谢谢

jmeter jsonpath
1个回答
0
投票
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData()) 0.upto(json.size() -1 , { idx -> if (json.get(idx).Relationship.find { it.Ref.id.equals('00000000000000000000000004640254') } != null) { vars.put('id', json.get(idx).id as String) return } })

更多信息:

Apache Groovy - Parsing and producing JSON

Apache Groovy - Why and How You Should Use It

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