Friday, March 13, 2015

JSON Objects

 Objects in JSON can be created using JavaScript, here objects can be anything. It can be unordered set of name or value pairs. Defining object in JSON has some rules and  while defining JSON Object it must be kept in notice that objects are always enclosed in curly braces starting with { and ending with } , name are followed by ‘.’(colon) and they are separated by ,(comma).

Syntax:

       var json_obj = {};  

Example:

 <!DOCTYPE html>  
 <html>  
 <head>  
 <title>JSON Object</title>  
 </head>  
 <body>  
         <h1>An Example of JSON Object</h1>  
 <p>Website Name: <h4 id="demo1"></h4></p>  
 <p>Website URL: <h4 id ="demo2"></h4></p>  
 <script language="javascript">  
 varjson_obj = { "Name" : "Workshop", "url":"www.nirajanghimireyworkshop.blogspot.com.com"};  
 document.getElementById("demo1").innerHTML = json_obj.Name;  
 document.getElementById("demo2").innerHTML = json_obj.url;  
 </script>         
 </body>  
 </html>  

No comments:

Post a Comment