[英]Error with Cannot convert undefined or null to object
The code here i recently cant start the code cause error with cannt convert undefined or null to object : 我最近在这里无法启动代码,导致无法将undefined或null转换为object导致错误:
Utils.getCardsInSets((ERR, DATA) => {
if (!ERR) {
allCards = DATA;
console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
} else {
console.log("An error occurred while getting cards: " + ERR);
}
});
Error that showed on console 控制台上显示的错误
console.log("Card data loaded. [" + Object.keys(DATA).length + "]");
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Utils.getCardsInSets (/root/test/index.js:37:52)
at Request.request [as _callback] (/root/test/utils.js:41:13)
at Request.self.callback (/root/test/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/root/test/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/root/test/node_modules/request/request.js:1085:12)
Your Utils.getCardsInSets
returning undefined
or null
DATA
. 您的
Utils.getCardsInSets
返回undefined
或null
DATA
。 In the above code you are not passing any query params to the method, check whether need to pass any params or not. 在上面的代码中,您没有将任何查询参数传递给该方法,请检查是否需要传递任何参数。
If what ever doing is correct, then method is returning undefined/null
based on certain condition. 如果所做的一切正确,则方法将根据特定条件返回
undefined/null
。 Just check for DATA
then go for its keys length. 只需检查
DATA
然后确定其密钥长度即可。
Utils.getCardsInSets((ERR, DATA) => {
if (!ERR) {
allCards = DATA;
var datalength = (!!DATA) ? Object.keys(DATA).length : 0;
console.log("Card data loaded. [" + datalength + "]");
} else {
console.log("An error occurred while getting cards: " + ERR);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.