Introduction
JSON is the JavaScript Object Notation. It is a lightweight format for data interchange.
In the old days web services use XML as primary data transmission medium with all other applications.
But JSON is a more lightweight and effient medium for data transmission compared to XML.
The following is the basis syntax of JSON:
- var emp= {"EmpName":"Chandradev"
- ,
- "EmpCode":"3007"
- }
- {"employees":[
- {"firstName":"Chandradev", "lastName":"Sah"},
- {"firstName":"Rajan", "lastName":"Prasad"},
- {"firstName":"Suraj", "lastName":"Kumar"}
- ]}
Using JSON in JavaScript
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript">
- var emp= {"EmpName":"Chandradev"
- ,
- "EmpCode":"3007"
- }
-
- alert(emp.EmpCode);
- alert(emp.EmpName);
-
- </script>
-
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
-
- </div>
- </form>
- </body>
- </html>
Advantages of JSON
- JSON is an easier to use alternative of XML
- JSON is a simple data exchange pertern that helps to communicate between JavaScript and server-side technology such as ASP.Net, PHP, JSP, CGI and so on
- JSON is a lightweight data interchange format
- JSON is language independent
- JSON is "self-describing" and easy to understand
In the .Net world we can also expose JSON data to the outside using WCF, ASP.Net and MVC. I will be writing an article on this topic very soon.