Thursday, 22 October 2015

What is JSON.parse ?

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!

No comments:

Post a Comment

Interactive CSS Button Designer Tool – Free & Fast

What is Button ?                               Button is an element of HTML. HTML is used to design Web Pages, Websites and Web applications...