Grow your CSS skills. Land your dream job.

Loop through JSON data help needed..

  • # June 21, 2013 at 9:19 am

    HI folks,

    Can someone please tell me how I can get the url for each rendition/item of this json data?

    { “items” : [ { “renditions” : [ { “audioOnly” : false,
    “controllerType” : “DEFAULT”,
    “displayName” : “361_NHS-condomneg#Expert_UB-H264-1024.mov”,
    “encodingRate” : 963000,
    “frameHeight” : 576,
    “frameWidth” : 1024,
    “id” : 33388781001,
    “referenceId” : null,
    “remoteStreamName” : null,
    “remoteUrl” : null,
    “size” : 16553283,
    “uploadTimestampMillis” : 1250021595080,
    “url” : “/25938593001/25938593001_33388781001_361-NHS-condomneg-Expert-UB-H264-1024.mp4″,
    “videoCodec” : “H264″,
    “videoContainer” : “MP4″,
    “videoDuration” : 137558
    },
    { “audioOnly” : false,
    “controllerType” : “DEFAULT”,
    “displayName” : “361_NHS-condomneg#Expert_UB-H264-1024.mov”,
    “encodingRate” : 571000,
    “frameHeight” : 268,
    “frameWidth” : 480,
    “id” : 33388757001,
    “referenceId” : null,
    “remoteStreamName” : null,
    “remoteUrl” : null,
    “size” : 9810270,
    “uploadTimestampMillis” : 1250021535074,
    “url” : “/25938593001/25938593001_33388757001_361-NHS-condomneg-Expert-UB-H264-1024.mp4″,
    “videoCodec” : “H264″,
    “videoContainer” : “MP4″,
    “videoDuration” : 137558
    },

    I’m currently trying to use:

    for (var i=0; i

    var it = jsonData[“renditions”];

    alert(it.url);

    }

    But keep getting ‘undefined’, can anyone please help?

    Thankyou

    # June 21, 2013 at 9:35 am

    Did you parse the JSON data first? Try:

    var jsonObject = JSON.parse(jsonData);
    for (var i =0; i < jsonObject.renditions.length; i++) {
    alert(jsonObject.renditions.url);
    }

    # June 21, 2013 at 9:45 am

    Thanks very much for your reply!

    I have tried but get an error:

    Error: SyntaxError: JSON.parse: unexpected character

    # June 21, 2013 at 4:50 pm

    If that’s all your data you need to remove the last `,` and add `] } ] }` instead (close renditions array, close object, close items array, close object). Tested and worked.

    # June 26, 2013 at 9:00 am

    Thanks for the reply.

    Thats not all the data, there is quite a bit more.

    I still get an error with this line:

    Timestamp: 6/26/2013 2:00:02 PM
    Error: SyntaxError: JSON.parse: unexpected character
    Line: 39

    var jsonObject = JSON.parse(jsonData);

    Can anyone please help? My json data is valid I have validated it.

    Thankyou

    # July 5, 2013 at 4:50 am

    Hello there,

    I’m still struggling to get this working, can anyone please help me output the items?

    Here is the json url:

    http://api.brightcove.com/services/library?command=find_all_videos&video_fields=renditions&token=ZpwKJFMptqRXV-rtn5ZAuWfUYHgnHOQLmHltN90f9WZ7pde7raxS2w..&callback=response&noCacheIE=1371815630456

    Many thanks

    # July 5, 2013 at 6:53 am

    Your link returns JSONP, so you need a function declared to capture it and you don’t need to parse it. Here’s a demo using your JSON data:

    http://codepen.io/CrocoDillon/pen/wpzbx

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".