如何在特定类别中查找标题邮递员

问题描述 投票:0回答:1

大家! 我有一些这样的结构:

{ "total": 1,
    "data": [
        {
            "ca_equipment": [
                {
                    "cd_en": null,
                    "cd_st": "2019-12-17T00:00:00",
                    "ck_d_equipment": "gas_stove",
                    "ck_id": "0223427C700B495490E540C54D3B4528",
                    "ck_model": null,
                    "ck_point": "70C220F236F34CA78EEDC2F4F16EA067",
                    "cl_status": 1,
                    "cv_d_equipment": "Плита",
                    "cv_model_name": null,
                    "cv_number": "Газовая  плита : 1"
                },
             "ca_meter": [
                {
                    "cd_en": null,
                    "cd_st": "2019-13-17T00:00:00",
                    "ck_id": "B48D81DD4sdfds4594B68D7D6FD846A410",
                    "ck_model": "99A24F5100F449A99B2C452CA3A9107F",
                    "ck_point": "70C220F23gsds34CA78EEDC2F4F16EA067",
                    "cl_status": 1,
                    "cv_model_name": "sdf",
                    "cv_number": "325233"
                }
            ] }

例如,我想检查“ca_meter”是否包含 teg“cd_st”。这个“cd_st”也在“ca_equipment”中。 但我只需要检查“ca_meter”/ 请帮助我))

我确实喜欢这个:

 pm.test("cd_eninclude?",function(){    
    pm.expect(jsonData1.data[0].ca_meter[0]).include("cd_en");
  });
postman include
1个回答
0
投票

您可以通过

tests
选项卡进行测试
cd_st

const jsonData = JSON.parse(responseBody);

pm.test('Check  cd_st\'s year format', function () {
    // get cd_st
    const cd_st = jsonData.data[0].ca_meter[0].cd_st;

    // get date token
    const dateToken = cd_st.split('T')[0]

    // get year
    const year = dateToken.substr(0,4);

    // check year
    pm.expect(year).is.to.equal("2019")
});

结果

© www.soinside.com 2019 - 2024. All rights reserved.