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

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...