难以解析来自Google Calendar JSON Feed的数据 [英] difficulty parsing data from google calendar json feed
本文介绍了难以解析来自Google Calendar JSON Feed的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打印事件名称,事件时间并从我的Google日历中链接到日历.似乎无法弄清楚我在做什么错
I am trying to print the event name, event time and link to the calendar from my google calendar. Cant seem to figure out what am I doing wrong
首先,感谢社区为我提供了明确的指导.我正确获取了事件名称.但是事件的开始时间和链接显示为未定义.
First of all thanks to the community for giving me some solid direction on this one. I am getting the event name correctly. But the event start time and link is showing undefined.
我的jquery和html看起来像这样
My jquery and html looks like this
var event = '';
var gclaData = 'http://www.google.com/calendar/feeds/somugus%40gmail.com/public/full?orderby=starttime&sortorder=ascending&max-results=3&futureevents=true&alt=json';
$.getJSON(gclaData,function(data){
$.each(data.feed.entry, function(i){
event += '<div class="eventHolder">';
event += '<div class="eventTime">'+ data.feed.entry[i].gd$when.startTime+"</div>";
event += '<div class="eventName">'+ data.feed.entry[i].title.$t + "</div>";
event += '<div class="eLink">'+ data.feed.entry[i].link.href + "</div>";
event += '</div>';
});
$('#output').html(event);
});
这是我的小提琴 http://jsfiddle.net/sghoush1/HEZaK/12/
推荐答案
您需要做类似的事情
$.getJSON(gclaData,function(data){
$.each(data.feed.entry, function(i, entry){
event += '<div class="eventHolder">';
event += '<div class="eventTime">'+ entry.gd$when[0].startTime+"</div>";
event += '<div class="eventName">'+ entry.title.$t + "</div>";
event += '<div class="eLink">'+ entry.link[0].href + "</div>";
event += '</div>';
});
$('#output').html(event);
});
很少指针
- .each()将对象的引用作为回调的第二个参数传递,因此无需使用索引来获取属性
-
gd$when
属性是一个数组,因此您可能需要访问第一个元素 - 与
link
属性相同
- .each() pass the reference to the object as the second argument to the callback, so there is no need to use the index to get the properties
gd$when
property is an array, so you might need to access the first element- same of
link
property also
演示:小提琴
这篇关于难以解析来自Google Calendar JSON Feed的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文