SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Outputting JSON Data

    HI Folks,

    Can anyone please tell me how I can loop through the items and display each value?

    Here is my json:

    http://api.brightcove.com/services/l...=1373013911514

    I have this code so far, but nothing is outputted and no errors are generated.

    Code:
    for (var i = 0; i < jsonData.length; i++) { 
    
     alert(jsonData.d[0].frameWidth);
    
    
    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Indeed, that wouldn't work because the JSON object contains an array of 100 items instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,255
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Looking at the JSON that's returned, I'd say you need to do something like this:
    Code JavaScript:
    for (var i = 0; i < jsonData.items.length; i++) { 
        var renditions = jsonData.items[i].renditions;
        for (var j = 0; j < renditions.length; j++) { 
            console.log(renditions[j].frameWidth);
        }
    }


Tags for this Thread

Bookmarks

Posting Permissions

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