【发布时间】:2021-08-06 10:14:48
【问题描述】:
我需要一个显示值字段总和结果的测试 对于下面的响应正文并将其显示在邮递员的控制台上, 响应体中的值的数量是动态的:
以下数值之和的结果: "value": 108.45 "value": 147.28 “价值”:87.70 “价值”:20.00 “价值”:75.40 “价值”:87.70 “价值”:147.28 “价值”:87.70**
{
"detalhes": {
"respostaDetalhe": [
{
"origem": "PAY",
"path": "BITO",
"nivel": 1,
"chaveFonte": "VendaCanceladaDebito",
"status": {
"codigo": "S00001",
"mensagem": "Operação realizada com sucesso",
"origem": "PAY",
"detalhes": {
"detalhe": []
}
},
"valuees": {
"detalhe": [
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8211184686-8241102617"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 108.45
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8211184688-8241102917"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 147.28
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8881016351-9041105200"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 87.70
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8881016193-9041103402"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 20.00
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8881015351-9041096206"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 75.40
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8881015000-9041093300"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 87.70
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8211184688-8241102919"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 147.28
}
]
}
},
{
"niveisAnteriores": {
"nivel": []
},
"conteudos": {
"conteudo": [
{
"identificadores": {
"identificador": [
{
"nome": "CUPOM",
"x": "8881015351-9041096207"
},
{
"nome": "CHAVE_LINHA",
"x": "TOTAL_VENDA_CANC_DEBITO"
}
]
},
"value": 87.70
}
]
}
}
]
}
}
]
}
}
【问题讨论】:
-
到目前为止您尝试过什么?什么不起作用?
-
我试图识别第一个值字段但没有成功,下面的代码返回 undefined: const response = pm.response.json(); const respostadetalhe = response.detalhes["respostaDetalhe"]; const nivel=respostadetalhe["1"]; console.log(nivel);