我真的在我的代码中发生了这个奇怪的事情。因此,我从数据库获取数据,然后提取数据并将数据发送回机器人。到目前为止,一切都很好,但这是真正的问题。在从json数组发送数据时,我看到数据是从数组中以随机顺序发送的,而不是按照我的预期顺序发送。可能是什么原因?我如何解决它?
case 'summary':
var balance = "";
var transactionsummary = "";
var date = "";
flag = 0;
trx.getsummary(senderid).then(function (v) {
var obj = JSON.parse(v);
if (obj.balance2 != '-1') {
console.log("Entered");
balance = obj.balance2;
transactionsummary = obj.transactionsummary;
date = obj.date2;
flag = flag + 1;
}
if (flag > 0) {
for (var i = 0; i < balance.length; i++) {
console.log(i, balance[i]);
telegram.sendMessage(senderid, "Balance" + "||" + balance[i] + "||" + "transactionsummary" +
"||" + transactionsummary[i] + "date" + "||" + date[i]);
}
console.log(balance);
telegram.answerCallbackQuery(msg.id);
flag = 0;
} else {
telegram.sendMessage(senderid, "Your telegram ID is not registered,Kindly contact your bank");
telegram.answerCallbackQuery(msg.id);
}
});
break;
//When I logged the balance, I get the data in this order [5000,3000,1500] which is correct.
我在机器人中获得的响应以随机顺序发送数据。我真的不想要它,因为它改变了交易摘要的全部含义。