0
我使用以下循环和Google Scripts解析XML文件,但是其中一个位置的XML文件中缺少一个Childs。所以整个过程返回一个空值。我如何检索所有不为空的数据?Google Sheet脚本在循环过程中为空错误
> function stugas() {
> var live = new Array();
> var url ="http://xml.pinnaclesports.com/pinnacleFeed.aspx?sportType=Football&contest=no&sportSubType=NFL";
> var parameters = {method : "get", payload : ""}; var xml =
> UrlFetchApp.fetch(url, parameters).getContentText();
> var document = XmlService.parse(xml);
> var games = document.getRootElement().getChild('events').getChildren('event');
> if(document == null) {
> document.getRootElement().getChild('events').getChildren('event'); } for (var i=0; i < games.length; i++) {
> vegas=[games[i].getChildText('event_datetimeGMT'),games[i].getChild('participants').getChildren('participant')[0].getChildText('participant_name'),
> games[i].getChild('participants').getChildren('participant')[0].getChildText('visiting_home_draw'),
> games[i].getChild('participants').getChildren('participant')[1].getChildText('participant_name'),
> games[i].getChild('participants').getChildren('participant')[1].getChildText('visiting_home_draw'),
> /**games[i].getChild('periods').getChildren('period')[0].getChild('moneyline').getChildText('moneyline_visiting'),
> games[i].getChild('periods').getChildren('period')[0].getChild('moneyline').getChildText('moneyline_home'),**/
> games[i].getChild('periods').getChildren('period')[0].getChild('spread').getChildText('spread_visiting'),
> games[i].getChild('periods').getChildren('period')[0].getChild('spread').getChildText('spread_home'),
> games[i].getChild('periods').getChildren('period')[0].getChild('spread').getChildText('spread_adjust_visiting'),
> games[i].getChild('periods').getChildren('period')[0].getChild('spread').getChildText('spread_adjust_home'),
> games[i].getChild('periods').getChildren('period')[0].getChild('total').getChildText('total_points'),
> games[i].getChild('periods').getChildren('period')[0].getChild('total').getChildText('over_adjust'),
> games[i].getChild('periods').getChildren('period')[0].getChild('total').getChildText('under_adjust')]
>
>
> live.push(vegas);
> }
> return live; }
谢谢哈罗德,你修复 –