Introduction to the power of JSON
<!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>JSON Example</title>
</head>
<body>
<form id="form1" >
<div>
<p>Hello Spidey!</p>
<script type="text/javascript">
var formatAddress = function(address) {
return address.line1 + "\n" + address.line2 + "\n" + address.town + "\n" + address.country + "\n" + address.postCode;
}
var person = { name: "Peter Parker",
addresses : [
{line1: "8 Legs Spidey Lane",
line2: null,
postCode: "8888",
town: "Spiderville",
country: "USA",
toString: function() { return formatAddress(this)}
}
,
{line1: "1 Hulksux Avenue",
line2: "Flat B",
postCode: "666",
town: "GreenGiants",
country: "USA",
toString: function() { return formatAddress(this)}
}
]
};
alert(person.name);
for(var i=0; i < person.addresses.length; i++) {
alert(person.addresses[i].toString());
}
</script>
</div>
</form>
</body>
</html>
Posted in Uncategorized by Ben at April 25th, 2007.