Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Location
    Houston, TX
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    you can plug that url in here which makes it a bit more humanly readable

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    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;

  • #4
    New Coder
    Join Date
    Sep 2012
    Location
    Houston, TX
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    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,

    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>";
          }
       }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •