Posted By

crypticsoft on 02/04/11


Tagged

jquery json each


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

virendrakryadav
nehringryan
jillella


JSON Data loop


 / Published in: jQuery
 

URL: http://stackoverflow.com/questions/733314/jquery-loop-over-json-result-from-ajax-success

You have an array of objects/maps so the outer loop loops through those. The inner loop loops through the properties on each object element.

  1. $.each(data, function() {
  2. $.each(this, function(k, v) {
  3. /// do stuff
  4. });
  5. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: crypticsoft on February 4, 2011

Usage example:

#

JSON Data Array :

#

Array ( [0] => Array ( [name] => Silver Cinemas - Bell Road [loc] => 2710 West Bell Road Suite 1125, Phoenix, AZ - (602) 212-6743 [movies] => Array ( [0] => Array ( [name] => The Social Network [times] => 3:25pm [idate] => )

#
                //loop through theater listings
                $.each(data, function(j) {

                  html += "" + data[j]['name'] + "";
                  html += "" + data[j]['loc'] + "";

                  //loop through showtimes
                  $.each(data[j]['movies'], function() {

                    html += "";
                    html += "<strong>" + this.name + "</strong>";
                    html += "<em>" + this.times + "</em>";

                  });
                });

You need to login to post a comment.