使用 Jmeter Path Expression 筛选 json格式的返回信息

需求:要确认接口infoFeed中第7个位置是否返回了我需要的contentId

接口返回信息如下

{
    "code":10000,
    "message":"成功",
    "body":
    {
        "content":
        [
            {
                "feedId":0,
                "contentId":"670147e6b75430110c6",
                "contentType":1,
                "title":"测试文中商品",
                "weight":1,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/02/13/1550053038334303.png"
                    }
                ],
                "origin":"ztjy",
                "duration":0,
                "tags":
                [
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    },
                    {
                        "display":"wiki-3",
                        "id":868,
                        "name":"三级测试1",
                        "tagName":"三级测试1",
                        "fakeId":1000868
                    }
                ],
                "comments":3,
                "likes":2,
                "likeState":0,
                "forwards":6,
                "pv":0,
                "publishTm":1550052317000,
                "data":
                {
                },
                "openMode":0,
                "originUrl":""
            },
            {
                "feedId":0,
                "contentId":"c90136163f17f01107e",
                "contentType":3,
                "title":"无专辑单视频1",
                "weight":1,
                "images":
                [
                ],
                "origin":"ztjy",
                "duration":248,
                "tags":
                [
                    {
                        "display":"wiki-3,list-general,list-age",
                        "id":33,
                        "name":"父母成长",
                        "tagName":"父母成长",
                        "fakeId":1000033
                    },
                    {
                        "display":"wiki-3",
                        "id":195,
                        "name":"饮食营养",
                        "tagName":"饮食营养",
                        "fakeId":1000195
                    },
                    {
                        "display":"wiki-3",
                        "id":745,
                        "name":"自信培养",
                        "tagName":"自信培养",
                        "fakeId":1000745
                    },
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    },
                    {
                        "display":"wiki-2",
                        "id":867,
                        "name":"二级测试2",
                        "tagName":"二级测试2",
                        "fakeId":1000867
                    },
                    {
                        "display":"wiki-3",
                        "id":869,
                        "name":"三级测试2",
                        "tagName":"三级测试2",
                        "fakeId":1000869
                    }
                ],
                "comments":94,
                "likes":0,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1545270318000,
                "data":
                {
                }
            },
            {
                "feedId":0,
                "contentId":"c9013627366c201106e",
                "contentType":2,
                "title":"推荐标题(单音频)",
                "weight":1,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/12/21/1545374259921099.png"
                    }
                ],
                "origin":"ztjy",
                "duration":287,
                "tags":
                [
                    {
                        "display":"wiki-3,list-general,list-age",
                        "id":33,
                        "name":"父母成长",
                        "tagName":"父母成长",
                        "fakeId":1000033
                    },
                    {
                        "display":"wiki-3",
                        "id":745,
                        "name":"自信培养",
                        "tagName":"自信培养",
                        "fakeId":1000745
                    },
                    {
                        "display":"list-age",
                        "id":831,
                        "name":"age宝宝不开心的age标签",
                        "tagName":"age宝宝不开心的age标签",
                        "fakeId":1000831
                    },
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    },
                    {
                        "display":"wiki-3",
                        "id":868,
                        "name":"三级测试1",
                        "tagName":"三级测试1",
                        "fakeId":1000868
                    }
                ],
                "comments":125,
                "likes":0,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1545288108000,
                "data":
                {
                }
            },
            {
                "feedId":0,
                "contentId":"c80133dc005b5011096",
                "contentType":13,
                "title":"音频专辑测试勿动",
                "weight":1,
                "images":
                [
                    {
                        "image":""
                    }
                ],
                "origin":"ztjy",
                "duration":0,
                "tags":
                [
                    {
                        "display":"wiki-3",
                        "id":195,
                        "name":"饮食营养",
                        "tagName":"饮食营养",
                        "fakeId":1000195
                    },
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-1",
                        "id":865,
                        "name":"年龄",
                        "tagName":"年龄",
                        "fakeId":1000865
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    },
                    {
                        "display":"wiki-2",
                        "id":867,
                        "name":"二级测试2",
                        "tagName":"二级测试2",
                        "fakeId":1000867
                    },
                    {
                        "display":"wiki-3",
                        "id":868,
                        "name":"三级测试1",
                        "tagName":"三级测试1",
                        "fakeId":1000868
                    },
                    {
                        "display":"wiki-3",
                        "id":869,
                        "name":"三级测试2",
                        "tagName":"三级测试2",
                        "fakeId":1000869
                    }
                ],
                "comments":0,
                "likes":0,
                "likeState":0,
                "forwards":0,
                "pv":534,
                "publishTm":1544672185000,
                "data":
                {
                    "channel":2,
                    "strengths":"撒大声地 鬼地方个发",
                    "standardPrice":0,
                    "parentPrice":0,
                    "parentFirstPrice":0,
                    "mediaTotal":0,
                    "alreadyBuy":0,
                    "guide":"更多精彩课程"
                }
            },
            {
                "feedId":0,
                "contentId":"c8013588fda2e0110a3",
                "contentType":14,
                "title":"视频专辑",
                "weight":1,
                "images":
                [
                ],
                "origin":"ztjy",
                "duration":0,
                "tags":
                [
                    {
                        "display":"dd1",
                        "id":194,
                        "name":"健康护理",
                        "tagName":"健康护理",
                        "fakeId":1000194
                    },
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-1",
                        "id":865,
                        "name":"年龄",
                        "tagName":"年龄",
                        "fakeId":1000865
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    },
                    {
                        "display":"wiki-2",
                        "id":867,
                        "name":"二级测试2",
                        "tagName":"二级测试2",
                        "fakeId":1000867
                    },
                    {
                        "display":"wiki-3",
                        "id":868,
                        "name":"三级测试1",
                        "tagName":"三级测试1",
                        "fakeId":1000868
                    },
                    {
                        "display":"wiki-3",
                        "id":869,
                        "name":"三级测试2",
                        "tagName":"三级测试2",
                        "fakeId":1000869
                    }
                ],
                "comments":0,
                "likes":0,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1545122108000,
                "data":
                {
                    "channel":2,
                    "strengths":"亮点介绍家长视频5555家长视频5555家长视频5555家长视频5555家长视频5555家长视频5555",
                    "standardPrice":0,
                    "parentPrice":0,
                    "parentFirstPrice":0,
                    "mediaTotal":15,
                    "alreadyBuy":0,
                    "guide":"更多精彩课程"
                }
            },
            {
                "feedId":0,
                "contentId":"67012d7ad354d0110a6",
                "contentType":1,
                "title":"123测试分享展示图片",
                "weight":1,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/11/23/1542960156877272.png"
                    }
                ],
                "origin":"ztjy",
                "duration":0,
                "tags":
                [
                    {
                        "display":"wiki-2",
                        "id":756,
                        "name":"小猪佩奇",
                        "tagName":"小猪佩奇",
                        "fakeId":1000756
                    },
                    {
                        "display":"wiki-1",
                        "id":864,
                        "name":"2~3岁",
                        "tagName":"2~3岁",
                        "fakeId":1000864
                    },
                    {
                        "display":"wiki-2",
                        "id":866,
                        "name":"二级测试1",
                        "tagName":"二级测试1",
                        "fakeId":1000866
                    }
                ],
                "comments":40,
                "likes":5,
                "likeState":0,
                "forwards":13,
                "pv":0,
                "publishTm":1542959864000,
                "data":
                {
                },
                "openMode":0,
                "originUrl":""
            },
            {
                "feedId":0,
                "contentId":"ea44ca59201839732a6c",
                "contentType":1,
                "title":"0320测试安",
                "weight":0,
                "images":
                [
                ],
                "largeImage":"",
                "origin":"ztjy",
                "duration":0,
                "tags":
                [
                ],
                "comments":0,
                "likes":0,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1553063237000,
                "author":
                {
                    "id":"62051284b5086d800851",
                    "type":3,
                    "name":"测试安",
                    "image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/03/20/1553062272681485.png",
                    "honor":"测试",
                    "iconUrl":"http://snsimg.ztjystore.cn/ztnew/edu/cover/2018/05/22/1526997733643766.png",
                    "follow":0,
                    "source":8
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":""
            },
            {
                "feedId":0,
                "contentId":"01170d5c64a311e88952",
                "contentType":1,
                "title":"儿童绘本的发展 培养孩子多元化",
                "weight":0,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751189265611.jpg"
                    }
                ],
                "largeImage":"",
                "origin":"qpx",
                "duration":0,
                "tags":
                [
                ],
                "comments":47,
                "likes":1,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1493654400000,
                "author":
                {
                    "type":3,
                    "follow":0
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":"http://m.qpx.com/yuer/xuelingqian/qinzi/218657.html"
            },
            {
                "feedId":0,
                "contentId":"1200a60064a311e88952",
                "contentType":1,
                "title":"这2种鸡蛋的吃法,儿童最不宜 再不看就晚了!",
                "weight":0,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751217990386.jpg"
                    },
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751218629691.jpg"
                    },
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751218178121.jpg"
                    }
                ],
                "largeImage":"",
                "origin":"qpx",
                "duration":0,
                "tags":
                [
                ],
                "comments":7,
                "likes":1,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1498233600000,
                "author":
                {
                    "type":3,
                    "follow":0
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":"http://m.qpx.com/yuer/xuelingqian/yinshi/233167.html"
            },
            {
                "feedId":0,
                "contentId":"13176fce64a311e88952",
                "contentType":1,
                "title":"小儿直肠脱垂的鉴别诊断 怎么治疗",
                "weight":0,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751219944397.jpg"
                    }
                ],
                "largeImage":"",
                "origin":"qpx",
                "duration":0,
                "tags":
                [
                ],
                "comments":7,
                "likes":1,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1497801600000,
                "author":
                {
                    "type":3,
                    "follow":0
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":"http://m.qpx.com/yuer/xuelingqian/jibing/230238.html"
            },
            {
                "feedId":0,
                "contentId":"13add6c664a311e88952",
                "contentType":1,
                "title":"儿童“生长痛” 跟缺钙无关",
                "weight":0,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751220709399.jpg"
                    }
                ],
                "largeImage":"",
                "origin":"qpx",
                "duration":0,
                "tags":
                [
                ],
                "comments":7,
                "likes":1,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1497801600000,
                "author":
                {
                    "type":3,
                    "follow":0
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":"http://m.qpx.com/yuer/xuelingqian/jibing/199065.html"
            },
            {
                "feedId":0,
                "contentId":"1461099464a311e88952",
                "contentType":1,
                "title":"宝宝发烧“抽抽了”太吓人!“热性惊厥”到底",
                "weight":0,
                "images":
                [
                    {
                        "image":"http://ztjy-img-dev.szytest.com/article/2018/05/31/1527751221378024.jpg"
                    }
                ],
                "largeImage":"",
                "origin":"qpx",
                "duration":0,
                "tags":
                [
                ],
                "comments":6,
                "likes":1,
                "likeState":0,
                "forwards":0,
                "pv":0,
                "publishTm":1497974400000,
                "author":
                {
                    "type":3,
                    "follow":0
                },
                "data":
                {
                },
                "openMode":0,
                "originUrl":"http://m.qpx.com/yuer/xuelingqian/jibing/232901.html"
            }
        ],
        "ad":
        {
            "ads":
            [
            ],
            "code":10002,
            "message":"",
            "space":
            {
                "spaceId":1007,
                "width":480,
                "height":320
            }
        }
    }
}

每一次都从用肉眼去找到第7条信息比较浪费时间

可以观察json的返回信息结构

使用json Path Tester 视图,在Jmeter Path Expression 中输入 $.body.content[6] ,即可直接找到第七条内容

原文地址:https://www.cnblogs.com/AliceAn/p/10578501.html