使用JMeter从JSON响应中提取某些数据

时间:2015-04-30 12:37:55

标签: json jmeter beanshell

我试图提取所有"现金"从SmallerList(到列表或数组)中的值并将它们相互比较,然后在新请求中使用最高值。

我一直在尝试在BeanShell PostProcessor中编写脚本并失败。 有什么建议?感谢

{
    "SomeList": {
        "SmallerList": [{
            "name": "aaa",
            "sample": "Hrazerggsl2",
            "NO": "156576321467",
            "data": "917",
            "xyzxyz": "TAKEOUT",
            "dadada": "64,04 USD",
            "cash": "64,04 USD",
            "asdasde": "0,00 USD",
            "asdasdw": "833248",
            "asdasdd": 0,
            "dsdfi": true,
            "ewqwe": false,
            "ewqewq": false,
            "irqfsais": true,
            "gggggg": false,
            "asdasda": false,
            "gffffv": false
        }, {
            "name": "aaa",
            "sample": "Hrazerggsl2",
            "NO": "156576321467",
            "data": "917",
            "xyzxyz": "TAKEOUT",
            "dadada": "94,04 USD",
            "cash": "154,04 USD",
            "asdasde": "0,00 USD",
            "asdasdw": "833248",
            "asdasdd": 0,
            "dsdfi": true,
            "ewqwe": false,
            "ewqewq": false,
            "irqfsais": true,
            "gggggg": false,
            "asdasda": false,
            "gffffv": false
        }, {
            "name": "aaa",
            "sample": "Hrazerggsl2",
            "NO": "156576321467",
            "data": "917",
            "xyzxyz": "TAKEOUT",
            "dadada": "64,04 USD",
            "cash": "624,04 USD",
            "asdasde": "0,00 USD",
            "asdasdw": "833248",
            "asdasdd": 0,
            "dsdfi": true,
            "ewqwe": false,
            "ewqewq": false,
            "irqfsais": true,
            "gggggg": false,
            "asdasda": false,
            "gffffv": false
        }],
        "drqwname": "aadasdaa",
            "sample": "Hdasdrazerggsl2",
            "NO": "156576321467",
            "data": "917",
            "xyzxyz": "TAKEOUT",
            "dadada": "64,04 USD",
            "cash": "64,04 USD",
            "asdasde": "0,00 USD",
            "asdasdw": "833248",
            "asdasdd": 0,
            "dsdfi": true,
            "ewqwe": false,
            "ewqewq": false,
            "irqfsais": true,
            "gggggg": false,
            "asdasda": false,
            "gffffv": false
    },
    "list": {
        "payment": [{
            "name": "asdasdasdasd"
        }, {
            "name": "asdasrqweqwe"
        }, {
            "name": "asgfdsf"
        }, {
            "name": "asdfasdfa"
        }],
        "name": "dad"
    },
    "success": true
}

1 个答案:

答案 0 :(得分:0)

使用JSON Path Extractor。它非常易于使用。

检查 this 以查找要使用的路径表达式。 (向下滚动到部分 - XPath和JSONPath之间的差异)

在您的情况下,$..cash将返回以下给出的所有cashallcash是我使用的变量。

allcash=["64,04 USD","64,04 USD","154,04 USD","624,04 USD"]
allcash_1=64,04 USD
allcash_2=64,04 USD
allcash_3=154,04 USD
allcash_4=624,04 USD