<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yuiloader/yuiloader-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/json/json-min.js"></script>

</HEAD>

<BODY onclick="test()">

</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test() {
var jsonString = '{  "category" : [';
jsonString +='{ "animal" : "Cat",  "message" : "Meow"  },';
jsonString +='{ "animal" : "Dog",  "message" : "Woof"  },';
jsonString +='{ "animal" : "Cow",  "message" : "Moo"   },';
jsonString +='{ "animal" : "Duck", "message" : "Quack" },';
jsonString +='{ "animal" : "Lion", "message" : "Roar"  }';
jsonString +='] }';
 
// Parsing JSON strings can throw a SyntaxError exception, so we wrap the call
// in a try catch block
try {
    var prod = YAHOO.lang.JSON.parse(jsonString);
 alert(prod.category[1].animal);
}
catch (e) {
    alert("Invalid product data");
}

}
//-->
</SCRIPT>

+ Recent posts