data ={
"message": "操作成功!",
"code": 200,
"data": {
"records": [
{
"number": "",
"customerDTO": {
"level": 0,
"city": {
"id": 440300
},
"statusShow": 2,
"tags": [],
"customerContactsDTOS": [
{
"phone": "",
"customerId": 202,
"name": "",
"duty": "",
"id": 252
}
],
"number": "",
"followers": [
{
}
],
"province": {
"id": 440000
},
"name": "比3",
"id": 202,
"businessType": {
},
"status": {
}
},
"proposeTime": "2022-11-29 16:13:18",
"followers": [
{
}
],
"name": "",
"demandContentDTOS": [
{
"proposeTime": "",
"id": 123,
"sysAttachmentDTOS": [
{
}
],
}
],
}
],
"total": 33,
"size": 2
},
}
1、判断多重嵌套中元素出现的次数,如:判断元素customerDTO出现的次数
var jsondata = JSON.parse(responseBody)
console.log(jsondata)
var data = jsondata["data"]["records"]
total = 0
for (var data_item of data){
for (var b in data_item){
if (b == "customerDTO"){
total = total +1
}
}
}
if (total == 10){
tests["查询成功"] = total == 10
}
else if (total != 10){
tests["查询失败"] = total != 10
}
2、如果需要设置某个value为变量,只需要
var data = jsonData["data"]
for (var data_item of data){
for(var b in data_item){
if(b == "id"){
postman.setEnvironmentVariable("id",data_item[b])
}
}
}