JSON is Javascript object notation . this is also a part of my learning . bcoz Its a popular data interchange format between clients and servers.
Json is basically a lightweight data interchange format. earlier we used to with XML and HTML and many more .But Json is lightweight , Easy to understand , language independent and self describing.
As we know that Server cannot send any object directly to client . so it need any middleware which can understandable both the side so through Json, server send any query as a string type and on client side it can easily be parsed as Object .So basically in laymen language json is a string , which can be easily converted into object and also object to string.
lets take a example.
1.)
{"student": [
{ "firstName":"tom" , "lastName":"decker" },
{ "firstName":"varun" , "lastName":"jain" },
{ "firstName":"lexia" , "lastName":"woodhouse" }
]
}
2.)
'{
"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }]}'
"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }]}'
so you can see how both look similar but First one is object and Second one is String.
so object to string and string to object .
JSON.stringify(data); - this convert into string format.
JSON.parse(data); - this convert into javascript object .
Dear Varun Jain,
ReplyDeleteI am BJP-SAD Candidate from Ludhiana West for Punjab Assembly Election for which polling will be held on January 30, 2012.
I request you to link to my blog at www.rajinderbhandari.blogspot.com
Kindly vote and support me. I request you to use your expertise with computer and internet to promote my messages to reach the voters.
I apologize if you consider my message as an intrusion.
Prof Rajinder Bhandari