Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用callbackWrapper函数解析.html页面时出现问题_Javascript_Json_Node.js - Fatal编程技术网

Javascript 使用callbackWrapper函数解析.html页面时出现问题

Javascript 使用callbackWrapper函数解析.html页面时出现问题,javascript,json,node.js,Javascript,Json,Node.js,我试图提取类似json的结构中的所有“id”,如下所示: callbackWrapper({ "scoreboard": [ { "day":"", "games":[ { "id":"2433023", "lastUpdated":"1518108600", "updatedTimestamp":"2018-02-08 11:50:45",

我试图提取类似json的结构中的所有“id”,如下所示:

callbackWrapper({

    "scoreboard": [
    {
        "day":"",
        "games":[
        {
             "id":"2433023",
             "lastUpdated":"1518108600",
             "updatedTimestamp":"2018-02-08 11:50:45",
             "conference":"all-conf southland northeast",
             "gameState":"final",
             "startDate":"2017-03-14",
             "startDateDisplay":"Mar. 14",
             "startTime":"6:40 PM ET",
             "startTimeEpoch":"1489531200",
             "currentPeriod":"",
             "finalMessage":"Final",
      etc....
我的nodejs文件中有以下内容:

request({

    url: url,
    json: true

}, function (error, response, body) {

    try {

        var mmSchedule = body;

        console.log(mmSchedule) // PRINT THE PAGE CONTENTS

        for (var i = 0; i < body["scoreboard"]["games"].length; i++) {

            console.log("lenght: ", mmSchedule["scoreboard"]["games"].length); <--- DOESNT WORK!!!

        }

    }

}
请求({
url:url,
json:true
},函数(错误、响应、正文){
试一试{
var mmSchedule=主体;
console.log(mmSchedule)//打印页面内容
对于(变量i=0;iconsole.log(“lenght:”,mmSchedule[“scoreboard”][“games”].length);
scoreboard
是一个对象数组。您需要多循环一次才能循环,或者如果数组中只有一个项目,您可以只使用
body[“scoreboard”][0][“day”][“games”].length
无效…文件中将有多个“id”。根据您的json结构,您将获得游戏id:body.scoreboard[0]。games[0]。id,您的id将不在day下,其in gamesError将抛出“TypeError:无法读取未定义的属性“0”您好@Learn2Code,您能告诉我您的代码您现在写了什么吗?TypeError:无法读取未定义的属性“0”获取此错误。