Why is that JSON feed returning an undefined variables while working for other variable? What am I doing wrong or overlooking? Thanks.
+2
A:
If you take a look at the contents in response:
curl http://gdata.youtube.com/feeds/users/kaycor/favorites?alt=json-in-script&callback=mycallback
You see that entry.media$group and entry.yt$statistics are not there:
gdata.io.handleScriptLoaded({
"feed": {
// snip ...
"entry": [{
// snip ...
"media$group": {
"media$category": [{
// snip ...
}],
"media$title": {
// snip ...
}
}
}]
}
});
Edit: Not all items contain the media$content
array, so you should modify your each block to something like this:
$.each(data.feed.entry, function(i, item){
var uploader = item['author'][0]['name']['$t'];
if (item['media$group']['media$content']) {
var URL = item['media$group']['media$content'][0]['url'];
var thum = item['media$group']['media$thumbnail'][0]['url'];
}
});
I wrote a quick test script for this and with the if clause in place, it did not throw errors anymore.
Priit
2010-01-06 08:09:27
@Priit, thanks for your reply. You're right, I just notice that the returned data from the account I was using is no longer returning those data since I retrieved the data earlier and was just now assigning variables. Updated my post. Still getting an error when assigning var to returned data.
2010-01-06 08:29:29
@Priit, thanks a lot for your continuous help. Vote up for you sir. Almost there (thumb var does not work for some reason even with an if statement). See my latest update above and let me know if you have any suggestions.
2010-01-06 22:05:35