Python接口测试 返回结果取相同名称参数中任意一个值

    科技2022-07-10  153

    业务需求:从返回结果取相同名称为id的参数中第2个值作为其他接口调用的入参。

    返回结果:

    {

        "rst": 0,

        "msg": "获取成功",

        "data": [

            {

                "id": 1226,

                "status": 1,

                "create_dt": "2019-07-30 14:23:59",

                "create_user_id": 21,

                "venue_id": 3189,

                "name": "阿尔法狗的测试场馆",

                "is_clubfree": 1,

                "boxes": [

                    {

                        "id": 1132,

                        "status": 1,

                        "venue_id": 3189,

                        "venue_area_id": 1226,

                        "create_dt": "2019-04-29 18:05:10",

                        "create_user_id": 8,

                        "sn": "918190",

                        "show_title": "TAKE TEST",

                        "bg_url": "",

                        "logo_url": "https://test.cn//static/upload/venue/logo/3189.jpeg?t=1563505254",

                        "owner_title": " 阿尔法狗的测试场馆"

                    },

                    {

                        "id": 1185,

                        "status": 1,

                        "venue_id": 3189,

                        "venue_area_id": 1226,

                        "create_dt": "2019-05-29 09:45:33",

                        "create_user_id": 21,

                        "sn": "922246",

                        "show_title": "健身工作室",

                        "bg_url": "",

                        "logo_url": "https://test.cn//static/upload/venue/logo/3189.jpeg?t=1563505254",

                        "owner_title": "TAKE 阿尔法狗的测试场馆"

                    }

                ]

            },

            {

                "id": 1736,

                "status": 1,

                "create_dt": "2020-06-24 10:30:26",

                "create_user_id": 21,

                "venue_id": 3189,

                "name": "自动化测试区",

                "is_clubfree": 0,

                "boxes": [

                    {

                        "id": 1153,

                        "status": 1,

                        "venue_id": 3189,

                        "venue_area_id": 1736,

                        "create_dt": "2019-05-20 12:08:53",

                        "create_user_id": 21,

                        "sn": "921210",

                        "show_title": "自动化测试区",

                        "bg_url": "",

                        "logo_url": "https://test.cn//static/upload/venue/logo/3189.jpeg?t=1563505254",

                        "owner_title": " 阿尔法狗的测试场馆"

                    }

                ]

            }

        ]

    }

     

    成功运行代码如下:

    vid = r.json()['data'][1]['id']

    代码解析 vid = r.json()['data'][1]['id'] //从响应数据提取出场馆区域列表中第二个id,定义一个变量or方法名为:vid

    json()['data'][1]['id'] 详细说明

    json():响应结果

    ['data']:数据集合

    [1]:数据1

    ['id']:数据1里面包含的字段

     

    希望对刚接触Python接口测试的同学有所帮助,也希望大家多多点赞收藏转发,您的鼓励是对我付出最大的支持!~

    Processed: 0.017, SQL: 8