CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   Parsing JSON - Finding element paths (http://www.codingforums.com/showthread.php?t=276021)

erebus 10-10-2012 03:20 PM

Parsing JSON - Finding element paths
 
I've gotten some help with working with my JSON replies... however im having alot of troubles determining the right path to elements of the reply. Is there a simplier way or perhaps a software that will better layout the JSON reply so i can see the objects more clearly?

For example, I'm getting a JSON reply from the youtube API and im trying to get the path to the first video in the list of 3 ive requested... i think it's something like this...

title = base.entry[0].title
link = base.entry[0].link[0].href
thumbnail = base.entry[0].media$thumbnail[0].url
info = base.entry[0].media$description.$t

am i in the right ballpark on these refrences?

the JSON reply can be pulled up here as it appears to be to long to paste into a code bracket

https://gdata.youtube.com/feeds/api/...3&v=2&alt=json

xelawho 10-10-2012 03:35 PM

you can plug that url in here which makes it a bit more humanly readable

xelawho 10-10-2012 04:29 PM

looking at it, I think the last two would be better one level deeper, into the media$group object, like this:

Code:

var thumbnail = base.entry[0].media$group.media$thumbnail[0].url;
var info = base.entry[0].media$group.media$description.$t;


erebus 10-10-2012 04:58 PM

Quote:

Originally Posted by xelawho (Post 1278375)
you can plug that url in here which makes it a bit more humanly readable

That is bookmarked and a great new reference, thank you very very much for that... my god just a few moments looking at that format and i had it all figured out, :D

Wrote the callback and function and i was dead on using the link you gave me!

If your interested at all or anyone out there would like some youtue API reference material here is the results

Callback:

Code:

<script
    type="text/javascript"
    src="https://gdata.youtube.com/feeds/api/videos?q=dayz&category=gaming&orderby=viewCount&max-results=3&v=2&alt=json-in-script&callback=showMyVideos">
</script>

Function:

Code:

function showMyVideos(data)
{
  var feed = data.feed;
  var base = feed.entry;
  for (var i = 0; i < base.length; i ++ )
  {
      document.getElementById("videologo" + (i + 1)).src = base[i].media$group.media$thumbnail[0].url;
      document.getElementById("videoname" + (i + 1)).innerHTML = base[i].title.$t;
      var status = base[i].media$group.media$description.$t;
      if (status.length > 76)
      {
      var statusubstr = status.substr(0,76)
      document.getElementById("videoinfo" + (i + 1)).innerHTML = "<p>" + statusubstr + "... </p>";
      }
      else
      {
      document.getElementById("videoinfo" + (i + 1)).innerHTML = "<p>" + status + " </p>";
      }
  }
}



All times are GMT +1. The time now is 02:43 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.