Jmeter接口自动化-4-使用jsonpath-JSON Extractor提取复杂响应中的数组及其他字段

一、jsonpath实时调试url

http://jsonpath.com/

 

 

 二、对于复杂响应的提取字段

    1.json字符串如下:

  

{
    "code": 0,
    "data": {
        "loanArray": [{
                "name": "测试测试",
                "priority": 0,
                "list": [{
                        "period": "24期",
                        "id": 66601
                    },
                    {
                        "period": "36期",
                        "id": 2792
                    }
                ]
            },
            {
                "name": "测试业测试",
                "priority": 1,
                "list": [{
                        "period": "24期",
                        "id": 66637
                    },
                    {
                        "period": "36期",
                        "id": 66633
                    }
                ]
            },
            {
                "name": "测试薪测试",
                "priority": 2,
                "list": [{
                        "period": "24期",
                        "id": 66646
                    },
                    {
                        "period": "36期",
                        "id": 66642
                    }
                ]
            },
            {
                "name": "测试享测试",
                "priority": 3,
                "list": [{
                        "period": "24期",
                        "id": 66655
                    },
                    {
                        "period": "36期",
                        "id": 66651
                    }
                ]
            },
            {
                "name": "我才测试",
                "priority": 4,
                "list": [{
                        "period": "24期",
                        "id": 666666
                    },
                    {
                        "period": "36期",
                        "id": 66622
                    }
                ]
            },
            {
                "name": "我房测试",
                "priority": 5,
                "list": [{
                        "period": "24期",
                        "id": 66619
                    },
                    {
                        "period": "36期",
                        "id": 66615
                    }
                ]
            },
            {
                "name": "我保测试",
                "priority": 6,
                "list": [{
                        "period": "24期",
                        "id": 66611
                    },
                    {
                        "period": "36期",
                        "id": 66607
                    }
                ]
            }
        ],
        "loanP": [{
                "id": 2,
                "keys": "CASH_FLOW",
                "name": "资金周转"
            },
            {
                "id": 6,
                "keys": "ASSET",
                "name": "购买货物/原材/设备"
            },
            {
                "id": 14,
                "keys": "ENALRGE",
                "name": "扩大生产/经营"
            },
            {
                "id": 15,
                "keys": "DECORATION",
                "name": "装修"
            },
            {
                "id": 16,
                "keys": "EDUCATION",
                "name": "教育支出"
            },
            {
                "id": 17,
                "keys": "MEDICAL",
                "name": "医疗"
            },
            {
                "id": 18,
                "keys": "WAGE",
                "name": "支付员工工资"
            },
            {
                "id": 19,
                "keys": "CONSUME",
                "name": "日常生活消费"
            },
            {
                "id": 20,
                "keys": "BUY_CAR",
                "name": "增购新车"
            }
        ]
    },
    "mask": "c1b8333a-732c-4666f-adad-b68b0b275f65",
    "msg": "success",
    "timestamp": 1575452653
}

取出loanArray数组下name="测试薪测试"的list下的id

方法如下:$..loanArray[?(@.name="测试薪测试")].list[0].id

 

posted @ 2019-12-04 18:59  旅行没有终点  阅读(2047)  评论(0编辑  收藏  举报