Friday, March 13, 2015

What are JSON Files ?

Files in JSON  are in ".json" format . These files contains the data that are to be interchanged while a client and a server communicate with one another. The data inside JSON files are in human-readable format so it is easy to read the data present inside a JSON file.

Example:



JSON File (demo.json)

 [  
 {  
 "Name": "PHP Blog",  
 "url": "http://www.nirajanghimireyworkshop.bogspot.com/search/label/php"  
 },  
 {  
 "Name": "JSON Blog",  
 "url": "http://www.nirajanghimireyworkshop.bogspot.com/search/label/json"  
 },  
 {  
 "Name": "Bootstrap Blog",  
 "url": "hhttp://www.nirajanghimireyworkshop.bogspot.com/search/label/Bootstrap"  
 }  
 ] 

HTML Document (json_files.html)

 <!DOCTYPE html>  
 <html>  
 <head>  
 <title>JSON</title>  
 </head>  
 <body>  
 <h1>An Example of JSON Files</h1>  
 <div id="id1"></div>  
 <script>  
  var tutorials = "demo.json";  
 myFunction(tutorials);  
 functionmyFunction(arr) {  
 var out = "";  
 vari;  
 for(i = 0; i<arr.length; i++) {  
 out += '<a href="' + arr[i].url + '">' +  
 arr[i].Name + '</a><br>';  
   }  
 document.getElementById("id1").innerHTML = out;  
 }  
 </script>  
 </body>  
 </html>

No comments:

Post a Comment