Reputation: 1623
I want to parse this json using jquery and each with a loop. I have only seen json examples where it is wrapped in array with a title such as results. How do I parse json like below...?
$.each(json.results, function() { console.log(this['title']); });
[{"title":"About Us","url_title":"about_us","entry_id":"155","channel_id":"2","author_id":"1","status":"open","entry_date":"1287508538","edit_date":"20101209122240","expiration_date":"0","about_body":"We are the greatest.","about_image":"","about_staff_title":"Joe","about_extended":"More about us.","color":"d12626"},{"title":"Contact Us","url_title":"contact_us","entry_id":"223","channel_id":"2","author_id":"1","status":"open","entry_date":"1291918929","edit_date":"20101209122310","expiration_date":"0","about_body":"Email us.","about_image":"","about_staff_title":"Bob","about_extended":"","color":"080480"}]
Upvotes: 1
Views: 982
Reputation: 100175
$.each(json, function() { console.log(this.title); });
Upvotes: 3
Reputation: 55688
Shouldn't it just be $.each(json, function() ... )
? Your JSON is an array, no wrapper, so just pass it directly to $.each()
.
Upvotes: 1