Thursday, 22 October 2015

What is json.stringify ?

What is json.stringify ?

If the stringify method sees an object that contains a toJSON method, it calls that method, and stringifies the value returned. This allows an object to determine its own JSON representation.

Example 1.
       JSON.stringify([1,2,3,4,"open","the","door"]);
Result : produces "[1,2,3,4,"open","the","door"]"

Example 2.

var mangtug = {
        name: "Manchester GTUG",
        meetup: "First Monday of every month",
        tags: ["gtug", "google", "manchester", "madlab"]
    },
    manjquery = {
        name: "Manchester jQuery Group",
        meetup: "First Tuesday of every month",
        tags: ["jquery", "javascript", "jresig", "madlab"]
    },
    hybrid = {
        name: "Hybrid!",
        meetup: mangtug.meetup,
        tags: manjquery.tags
    };

var madlabGroups = [mangtug, manjquery, hybrid];

Result :

[{"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"]}]

No comments:

Post a Comment

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

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