Parse JSON data using JQuery

Programming Tips-And-Tricks

A couple of very simple and intuitive code examples to parse data received in JSON format:

var resultJSON = '{"FirstName":"John","LastName":"Doe","Email":"johndoe@johndoe.com","Address":"123 dead drive"}';
var result = $.parseJSON(resultJSON);
$.each(result, function(k, v) {
//display the key and value pair
alert(k + ' is ' + v);
});

Or

var obj = $.parseJSON(resultJSON);
for (var prop in obj) {
alert(prop + " is " + obj[prop]);
}

Leave a Reply

Your email address will not be published. Required fields are marked *