What is JSON.parse ?
Returns the Object corresponding to the given JSON text. Takes a well-formed JSON string and returns the resulting JavaScript object.
Example 1
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );
Example 2
var jsonString = '[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]';
var myData = JSON.parse(jsonString);
$(document).ready(function() {
var $grouplist = $('#groups');
$.each(myData, function() {
$('<li>' + this.name + '</li>').appendTo($grouplist);
});
});
Result :
Manchester GTUG
Manchester jQuery Group
Hybrid!
Returns the Object corresponding to the given JSON text. Takes a well-formed JSON string and returns the resulting JavaScript object.
Example 1
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );
Example 2
var jsonString = '[{"name":"Manchester GTUG","meetup":"First Monday of every month","tags":["gtug","google","manchester","madlab"]},{"name":"Manchester jQuery Group","meetup":"First Tuesday of every month","tags":["jquery","javascript","jresig","madlab"]},{"name":"Hybrid!","meetup":"First Monday of every month","tags":["jquery","javascript","jresig","madlab"]}]';
var myData = JSON.parse(jsonString);
$(document).ready(function() {
var $grouplist = $('#groups');
$.each(myData, function() {
$('<li>' + this.name + '</li>').appendTo($grouplist);
});
});
Result :
Manchester GTUG
Manchester jQuery Group
Hybrid!
No comments:
Post a Comment