首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:无法读取未定义的房地产市场(第23行)

TypeError:无法读取未定义的房地产市场(第23行)
EN

Stack Overflow用户
提问于 2020-08-09 22:19:26
回答 1查看 101关注 0票数 0

TypeError:无法读取未定义的房地产市场(第23行)

我使用同一个数据库已经6个月没有接触到任何东西,它从未失败过,今天这个错误开始出现,我试图找出错误,但在收集数据时我找不到错误。

下面是我收集值的基础(您可以通过单击链接访问数据地图):

https://webhooks.mongodb-stitch.com/api/client/v2.0/app/oddsbf-dvyne/service/http/incoming_webhook/webhook0

下面是我使用的脚本:

代码语言:javascript
复制
  const response = UrlFetchApp.fetch("https://webhooks.mongodb-stitch.com/api/client/v2.0/app/oddsbf-dvyne/service/http/incoming_webhook/webhook0");
  const mongo_matches = JSON.parse(response.getContentText());
  const matches = mongo_matches.map(function(match) {
    var over = '-'
    var under = '-'
    if(match['markets']['over_25'] !== undefined && 
       match['markets']['over_25']['over']['odds'] !== undefined && 
       (match['markets']['over_25']['over']['odds']['availableToBack'].length > 0 &&
         match['markets']['over_25']['under']['odds']['availableToBack'].length > 0 )){
      over = match['markets']['over_25']['over']['odds']['availableToBack'][0] !== undefined ? match['markets']['over_25']['over']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['markets']['over_25']['over']['odds']['availableToLay'][0]['price']['$numberDouble']
      under = match['markets']['over_25']['under']['odds']['availableToBack'][0] !== undefined ? match['markets']['over_25']['under']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['markets']['over_25']['under']['odds']['availableToLay'][0]['price']['$numberDouble']
    }
    return [
      match['markets']['marketStartTime'],
      match['markets']['lastSaved'],
      match['markets']['competition'],
      match['markets']['homeTeam']['runnerName'],
      match['markets']['awayTeam']['runnerName'],
      match['markets']['homeTeam']['odds']['availableToBack'][0] !== undefined ? match['markets']['homeTeam']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['markets']['homeTeam']['odds']['availableToLay'][0]['price']['$numberDouble'],
        match['markets']['awayTeam']['odds']['availableToBack'][0] !== undefined ? match['markets']['awayTeam']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['markets']['awayTeam']['odds']['availableToLay'][0]['price']['$numberDouble'],
          match['markets']['draw']['odds']['availableToBack'][0] !== undefined ? match['markets']['draw']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['draw']['markets']['odds']['availableToLay'][0]['price']['$numberDouble'],
            under,
              over,
                ]; 
  });

给出错误的第23行是以下内容:

代码语言:javascript
复制
          match['markets']['draw']['odds']['availableToBack'][0] !== undefined ? match['markets']['draw']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['draw']['markets']['odds']['availableToLay'][0]['price']['$numberDouble'],
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-09 22:29:30

将第23行改为:

代码语言:javascript
复制
match['markets']['draw']['odds']['availableToBack'][0] !== undefined ? match['markets']['draw']['odds']['availableToBack'][0]['price']['$numberDouble'] : match['markets']['draw']['odds']['availableToLay'][0]['price']['$numberDouble'],

更新:

代码语言:javascript
复制
Logger.log(mongo_matches['draw'])
Logger.log(mongo_matches['matches'])

都返回null。这意味着您无法从空对象访问信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63331889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档