tests脚本:打印数组对象的数据

响应正文

[
    {
      "nodes": [
             {
                "id": 1503,
                "nodetype": "Event",
                "name": "技术人员的道路》的调查报告作批示",
                "shortname": null,
                "sourcedescription": "XXXX",
                "year": 1968,
                "datestr": "1968-07-21",
                "imglink": null,
                "videolink": null,
                "priority": 0.0,
                "iscorenode": true,
                "desc": "“大学还是要办的大学。"
            },    
        ], 
        "links": [
             {
                "source": ID,
                "relationname": "领导",
                "target": ID
            }
        ] 
    }

]

tests的脚本

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});


// 此方法计算返回数据的总条数
var data=JSON.parse(responseBody);
var truec=0;
var textarray=[];
for(var i=0;i<data.length;i++)
    {
        var count=i;        
        for(var j=0;j<data[i].nodes.length;j++){
            var jcount=j;
            var IId="id="+data[i].nodes[j].id;
            var Mname="name="+data[i].nodes[j].name;
            var iscorenode="iscorenode="+data[i].nodes[j].iscorenode;
            var message="第"+i+"组nodes的信息为";   
            console.log(message+" "+IId+"   "+iscorenode+"  "+Mname);  
            // 计算有几个核心球
            if(data[i].nodes[j].iscorenode){   
                //最好的处理方式是:把数据逐步存放数组中,最后打印出来  
                textarray[truec]=IId+","+iscorenode+","+Mname;
                //计算核心球的数量
                truec=truec+1;
            }  
        }
        /**/
        if(jcount!=null){
            jcount=jcount+1;
            jjcount="**********************第 "+i+" 组nodes的总数据条数为 "+jcount;
            console.log(jjcount);            
        }   
        
       if(truec!=null){
            truecj="**********************核心球一共有【 "+truec+" 】个,iscorenode=true****************";
             console.log(truecj);
       }
    }

if(count!=null){
    count=count+1
    console.log("**********************共有【 "+count+" 】对数据")
    //打印数组的值
    console.log(textarray)
}

在控制台查看结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值