This example we are using JSON in asp.net 3.5; Java Script Object Oriented Notation  is a choice over xml file, where a complex object can be serialized using Visual  Web developer Express Studio 2008.

Step: 1 Create a website http://manas6/aspnet.35/mm.JSONIntro1/

The intelligence of Visual Web Developer recognizes the object created in an external file

Step: 2 The editor of Visual Studio Express did not allow white spaces in JavaScript editor

JSON.js

// white spaces cuased syntax error

// don't break into lines

var external = '{"book": { "title": "ASP.NET AJAX", "author":"Internet Example","chapters": {"chapter": [ {"number": "1", "title":"Crash Course on JavaScript "}, {"number": "2", "title": "Introduction to JSON "}, {"number": "3", "title": "Introduction to Ajax Extension"} ]} }}';

 

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>mm.JSONINtro1: Simple internal external script</title>

</head>
<body>
<form id="form1" runat="server"><div id="sp1"></div>
<div>
<script type="text/javascript" src="JSON1.js"> </script>
<script language="JavaScript" type="text/javascript">
var doc = document.getElementById("sp1");
var result1 = ""; var result2 = "" ;
function do_json()
{
var injson = '{"book": { "title": "ASP.NET AJAX", "author":"Internet Example","chapters": {"chapter": [ {"number": "1", "title":"Crash Course on JavaScript "}, {"number": "2", "title": "Introduction to JSON "},{"number": "3", "title": "Introduction to Ajax Extension"} ]} }}';
var obj = eval("(" + injson + ")");
var exobj = eval("(" + external + ")");

for (var i = 0; i < obj.book.chapters.chapter.length; i++) {
document.write("<p>" +
obj.book.chapters.chapter[i].number + ": " +
obj.book.chapters.chapter[i].title + "</p>");
result1 += obj.book.chapters.chapter[i].number + ": " + obj.book.chapters.chapter[i].title + "<br/>";
}
//
for (var i = 0; i < exobj.book.chapters.chapter.length; i++) {

result2 += exobj.book.chapters.chapter[i].number + ": " + exobj.book.chapters.chapter[i].title + "<br/>";
}
doc.innerHTML += "<font color='Green' ><b>" + result1 + "</b></font> --------<br/>";
doc.innerHTML += "<font color='red'><i>" + result2 + "</i></font><br/>";
}
do_json();
</script>
</div>

</form>
</body>
</html>
 

Step: 3 runtime observation