• Jmeter后置处理器之Json提取器


     
    用法说明
     
      此提取器用于提取请求返回结果中的某个值或者某一组值,用法比正则表达式要简单,标准写法为$.key,其中key为返回结果map中的一个键,如果是多层则继续用.key进行即可,如果遇到key的value值为一个List,则使用.key[n],其中n为list中元素的编号,如下使用实例来说明下如何使用;
     

      而json提取器语法用分号隔开,应当与参数名称一一对应;
      匹配编号一样的需要用分号隔开,与参数名称一一对应;
      默认值同样用分号隔开,与参数名称一一对应;
     
      Json提取器语法说明
        完整的语法说明请见https://github.com/json-path/JsonPath
      调试方法:
        在View Result Tree中选择JSON Path Tester,即可展开如下图的右侧内容,输入表达式即可拿来测试书写的Json提取器表达式是否能正常工作:
        

      示例:

        请求URL:https://fe-api.zhaopin.com/c/i/sou?pageSize=60&cityId=765&workExperience=-1&education=-1&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95&kt=3

        返回的数据格式:

    {
        "recordsFiltered": 8,
        "data": [
            {
                "thisYear": 0,
                "hfyljg": "广州市养老机构",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "A(优秀)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-11-26 00:00:00",
                "hfgcyxzl": "",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "7695969a08c34ff18ee847437c295377",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "A(优秀)",
                "hfgcsm": "test",
                "createBy": null,
                "fwzl": "A(优秀)",
                "hflr": "test",
                "updateby": null,
                "rzlrmyd": "A(优秀)",
                "qtsmbz": "",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "广州市养老机构",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "A(优秀)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-11-26 00:00:00",
                "hfgcyxzl": "",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "7ef39120839641509a448022d8d19f1d",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "A(优秀)",
                "hfgcsm": "test",
                "createBy": null,
                "fwzl": "A(优秀)",
                "hflr": "test",
                "updateby": null,
                "rzlrmyd": "A(优秀)",
                "qtsmbz": "",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "增城区中新镇福和敬老院",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "C(一般)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-12-10 00:00:00",
                "hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "b0b9fcd09b01495a82f21cddd02dd2d0",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "B(良好)",
                "hfgcsm": "我很好",
                "createBy": null,
                "fwzl": "B(良好)",
                "hflr": "国家战士",
                "updateby": null,
                "rzlrmyd": "B(良好)",
                "qtsmbz": "没问题",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "增城区中新镇福和敬老院",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "C(一般)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-12-10 00:00:00",
                "hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "2576d5940acb48e1a55ddb56fd28e34f",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "B(良好)",
                "hfgcsm": "我很好",
                "createBy": null,
                "fwzl": "B(良好)",
                "hflr": "国家战士",
                "updateby": null,
                "rzlrmyd": "B(良好)",
                "qtsmbz": "没问题",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "增城区中新镇福和敬老院",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "C(一般)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-12-10 00:00:00",
                "hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "a9aafaa9c64a419c8eabae370f0dae31",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "B(良好)",
                "hfgcsm": "我很好",
                "createBy": null,
                "fwzl": "B(良好)",
                "hflr": "国家战士",
                "updateby": null,
                "rzlrmyd": "B(良好)",
                "qtsmbz": "没问题",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "增城区中新镇福和敬老院",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "C(一般)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-12-10 00:00:00",
                "hfgcyxzl": "4c698efd8744f5d4319bfc5d7a5d36c1",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "b64df74269cd4805a70fdd0b0b4a8cf9",
                "hfjlr": "市领导",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "B(良好)",
                "hfgcsm": "我很好",
                "createBy": null,
                "fwzl": "B(良好)",
                "hflr": "国家战士",
                "updateby": null,
                "rzlrmyd": "B(良好)",
                "qtsmbz": "没问题",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "中二机构",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "C(一般)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-08-04 00:00:00",
                "hfgcyxzl": "",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "c22175d30d7141248054a6a5db3618e3",
                "hfjlr": "白云区经办",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "C(一般)",
                "hfgcsm": "一般",
                "createBy": null,
                "fwzl": "C(一般)",
                "hflr": "刘贤",
                "updateby": null,
                "rzlrmyd": "C(一般)",
                "qtsmbz": "",
                "qcode": null,
                "remarks": null
            },
            {
                "thisYear": 0,
                "hfyljg": "中四机构",
                "updateDate": null,
                "ysq2": null,
                "con": null,
                "ysq3": null,
                "dpid": null,
                "ztpf": "A(优秀)",
                "createdate": null,
                "delFlag": "0",
                "hfrq": "2019-08-02 00:00:00",
                "hfgcyxzl": "",
                "createby": null,
                "updatedate": null,
                "updateBy": null,
                "ysq": null,
                "id": "23598ee7b0a140b49a84e96e8b63345d",
                "hfjlr": "白云区经办",
                "isdel": null,
                "createDate": null,
                "createtime": null,
                "message": null,
                "fwtd": "A(优秀)",
                "hfgcsm": "老人对机构评价不错",
                "createBy": null,
                "fwzl": "B(良好)",
                "hflr": "黄佩",
                "updateby": null,
                "rzlrmyd": "B(良好)",
                "qtsmbz": "",
                "qcode": null,
                "remarks": null
            }
        ],
        "draw": 0,
        "recordsTotal": 8
    }

    现在我们来提取职位的positionURL字段:

    1、在查看结果树中通过JSON Path Tester来调试json path

    2、添加JSON提取器,设置正确的参数,获取第一个positionURL

     输出结果:

    3、获取所有的positionURL

     输出结果:

    4、把所有的positionURL放到一个字段中

     输出结果:

    5、一次性提取多个字段,比如我们要提取第一个职位的jobName;salary;positionURL三个字段

     输出结果:

    Json Path表达式:

    JsonPath

    描述

    $

    根节点

    @

    当前节点

    .or[]

    子节点

    ..

    选择所有符合条件的节点

    *

    所有节点

    []

    迭代器标示,如数组下标

    [,]

    支持迭代器中做多选

    [start:end:step]

    数组切片运算符

    ?()

    支持过滤操作

    ()

    支持表达式计算

  • 相关阅读:
    「BZOJ2721」「LuoguP1445」 [Violet]樱花(数论
    「USACO08DEC」「LuoguP2921」在农场万圣节Trick or Treat on the Farm(tarjan
    「HNOI2008」「LuoguP3197」越狱(数论
    「CF779B」「LOJ#10201.」「一本通 6.2 练习 4」Sherlock and His Girlfriend(埃氏筛
    「LOJ#10072」「一本通 3.2 例 1」Sightseeing Trip(无向图最小环问题)(Floyd
    「LOJ#10068」「一本通 3.1 练习 3」秘密的牛奶运输(次小生成树
    「USACO15FEB」「LuoguP3121」审查(黄金)Censoring (Gold)(AC自动机
    「LOJ#10056」「一本通 2.3 练习 5」The XOR-longest Path (Trie
    「LOJ#10051」「一本通 2.3 例 3」Nikitosh 和异或(Trie
    「UVA644」 Immediate Decodability(Trie
  • 原文地址:https://www.cnblogs.com/DeryKong/p/13424633.html
Copyright © 2020-2023  润新知