javascript - jQuery JSON parse via $.each - Cannot get length of undefined -


i trying parse json response php call.

the returned data in json format, below:

{"success":true,  "venues":       [           {"id":237,"title":"country house hotel , restaurant","thumb_image":"thumb_combe-house-buttercups_3617067271.jpg","description":"","subtype":1},           {"id":579,"title":"abode exeter","thumb_image":"wvs.jpg","description":"","subtype":0},           {"id":484,"title":"anran luxury boutique","thumb_image":"wvs.jpg","description":"","subtype":0}       ] } 

however, when try use $.each function loop on it, returning error uncaught typeerror: cannot read property 'length' of undefined.

a snippet of code using perform $.each loop below.

$.each(data.venues, function() {     $.each(this, function(k, v) {         alert(k + ' ' + v);     }); }); 

it works expected, if parsejson data.

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(function() {  var data = $.parsejson('{"success":true,"venues":[{"id":237,"title":"country house hotel , restaurant","thumb_image":"thumb_combe-house-buttercups_3617067271.jpg","description":"","subtype":1},{"id":579,"title":"abode exeter","thumb_image":"wvs.jpg","description":"","subtype":0},{"id":484,"title":"anran luxury boutique","thumb_image":"wvs.jpg","description":"","subtype":0}]}');  $.each(data.venues, function() {                 $.each(this, function(k, v) {                     alert(k + ' ' + v);                 });             });  }); </script> </head> <body> 

demo: http://pascha.org/test/4.php


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -