简体   繁体   English

无法将未定义或空值转换为对象的错误

[英]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返回undefinednull 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.

相关问题 错误:无法将未定义或 null 转换为 object - Error: Cannot convert undefined or null to object 错误TypeError:无法将未定义或null转换为对象 - error TypeError: Cannot convert undefined or null to object 反应:错误:无法将未定义或 null 转换为 object - React: error: Cannot convert undefined or null to object 无法将未定义或null转换为对象 - Cannot convert undefined or null to object ReactJS 错误 TypeError:无法将 undefined 或 null 转换为对象 - ReactJS error TypeError: Cannot convert undefined or null to object 渲染错误:“TypeError:无法在 vue js 中将未定义或 null 转换为对象”? - Error in render: “TypeError: Cannot convert undefined or null to object” in vue js? UglifyJs引发错误:无法将未定义或null转换为对象 - UglifyJs throws error: Cannot convert undefined or null to object 在 Vue 组件上出现错误“无法将未定义或 null 转换为对象” - Getting an error “Cannot convert undefined or null to object” on Vue component 数据()中的Vue警告错误“类型错误:无法将未定义或空值转换为对象” - Vue warning Error in data() "TypeError: Cannot convert undefined or null to object" json数据错误未捕获的TypeError:无法将未定义或null转换为对象 - json data error Uncaught TypeError: Cannot convert undefined or null to object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM