Loading

Jmeter中【Json提取器】使用方法

添加插件方法

 json 提取器参数介绍

  • names of created variables :接收值的变量名,多个变量时用分号分隔
  • json path: json path表达式,也是用分号分隔
  • match no:0随机;n取第几个匹配值;-1匹配所有,后续引用用 变量名_N 取第N个值。
  • default values: 缺省值,匹配不到值的时候取该值

取响应json里面的第一个id值

{
  "code": 0,
  "data": {
    "total": 1611,
    "rows": [
      {
        "color": "red",
        "dueDate": 1583285312000,
        "ticketNo": "HCIMS201912050003",
        "todoType": 3,
        "serviceTicket": {
          "id": 1316,
          "ticketNo": "HCIMS201912050003",
          "spCode": "ICE0000",
          "customerId": 214,
          "dealerId": 1,
          "vehicleId": 1248,
          "rateId": null,
          "ticketStatus": 8,
          "fulfillmentStatus": 8,

$.data.rows[0].serviceTicket.id

取索引最后一个值

$.data.data[-1].id

取响应json里面多个值

提取某个索引区间访问内多个值

{
    "msg": "ok",
    "code": "0",
    "data": {
        "homecheckResult": [
            {
                "total": 2485,
                "list": [
                    {
                        "count": 2306,
                        "option1": 1,
                        "option2": null
                    },
                    {
                        "count": 104,
                        "option1": 2,
                        "list": [
                            {
                                "count": 35,
                                "option1": 2,
                                "option2": 1
                            },
                            {
                                "count": 27,
                                "option1": 2,
                                "option2": 2
                            },
                            {
                                "count": 15,
                                "option1": 2,
                                "option2": 3
                            },
                            {
                                "count": 27,
                                "option1": 2,
                                "option2": 4
                            }
                        ]
                    },

$.data.homecheckResult[0].list[1].list[0:5].count

提取符合索引区间范围的所有值

$..id

{
    "msg": "ok",
    "code": 0,
    "data": [
        {
            "aliasName": "",
            "code": "110000",
            "level": "province",
            "cityCode": "010",
            "name": "北京市",
            "id": 2
        },
        {
            "aliasName": "",
            "code": "120000",
            "level": "province",
            "cityCode": "022",
            "name": "天津市",
            "id": 3
        },
        {
            "aliasName": "",
            "code": "130000",
            "level": "province",
            "cityCode": "",
            "name": "河北省",
            "id": 4
        },
        {
            "aliasName": "",
            "code": "140000",
            "level": "province",
            "cityCode": "",
            "name": "山西省",
            "id": 5
        },
        {
            "aliasName": "",
            "code": "150000",
            "level": "province",
            "cityCode": "",
            "name": "内蒙古自治区",
            "id": 6
        },
        {
            "aliasName": "",
            "code": "210000",
            "level": "province",
            "cityCode": "",
            "name": "辽宁省",
            "id": 7
        },
        {
            "aliasName": "",
            "code": "220000",
            "level": "province",
            "cityCode": "",
            "name": "吉林省",
            "id": 8
        },
        {
            "aliasName": "",
            "code": "230000",
            "level": "province",
            "cityCode": "",
            "name": "黑龙江省",
            "id": 9
        },
        {
            "aliasName": "",
            "code": "310000",
            "level": "province",
            "cityCode": "021",
            "name": "上海市",
            "id": 10
        },
        {
            "aliasName": "",
            "code": "320000",
            "level": "province",
            "cityCode": "",
            "name": "江苏省",
            "id": 11
        },
        {
            "aliasName": "",
            "code": "330000",
            "level": "province",
            "cityCode": "",
            "name": "浙江省",
            "id": 12
        },
        {
            "aliasName": "",
            "code": "340000",
            "level": "province",
            "cityCode": "",
            "name": "安徽省",
            "id": 13
        },
        {
            "aliasName": "",
            "code": "350000",
            "level": "province",
            "cityCode": "",
            "name": "福建省",
            "id": 14
        }
    ]
}

$.data..id

通过满足某个条件值来获取

{
    "msg": "ok",
    "code": 0,
    "data": [
        {
            "dealerName": "成都金牛保时捷中心",
            "address": "成都",
            "dealerCode": "7000001",
            "city": "成都",
            "postalCode": "1",
            "pcName": "PC Chengdu I",
            "updateTime": 1565798400000,
            "createBy": "1",
            "sooDate": 38139,
            "province": "四川",
            "createTime": 1565798400000,
            "updateBy": "1",
            "id": 1,
            "dealerTel": "+86-28-8759-2911",
            "region": 3,
            "shortName": "CDJN",
            "dealerGroup": 3,
            "dealerNameEn": "Porsche Centre Chengdu Jinniu",
            "group": {
                "createBy": "system",
                "createTime": 1575216000000,
                "updateBy": null,
                "name": "Betterlife",
                "updateTime": null,
                "id": 3,
                "nameEn": "Betterlife"
            }

$.data[?(@.sooDate<38140)].province

把所有值都取出来

{
    "msg": "ok",
    "code": 0,
    "data": [
        {
            "dealerName": "成都金牛保时捷中心",
            "address": "成都",
            "dealerCode": "7000001",
            "city": "成都",
            "postalCode": "1",
            "pcName": "PC Chengdu I",
            "updateTime": 1565798400000,
            "createBy": "1",
            "sooDate": 38139,
            "province": "四川",
            "createTime": 1565798400000,
            "updateBy": "1",
            "id": 1,
            "dealerTel": "+86-28-8759-2911",
            "region": 3,
            "shortName": "CDJN",
            "dealerGroup": 3,
            "dealerNameEn": "Porsche Centre Chengdu Jinniu",
            "group": {
                "createBy": "system",
                "createTime": 1575216000000,
                "updateBy": null,
                "name": "Betterlife",
                "updateTime": null,
                "id": 3,
                "nameEn": "Betterlife"
            }
        },

 

$..*

取多个不同字段值

我想同时取出多个不同字段的值

例:

{
    "code": "0",
    "data": {
        "paymentNo": "202106090118460116",
        "pspId": "001",
        "payInfo": "https:\/\/qr.95516.com\/48020000\/65532106091201847132826151"
    },
    "message": "OK"
}

比如:我要取paymentNo、pspId、payInfo的变量值

  • 1、各选项均用分号";"隔离
  • 2、Default Values必填

 

 

posted @ 2020-05-09 12:24  Binzichen  阅读(1103)  评论(0编辑  收藏  举报