<!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>
'프로그램 언어 > 자바스크립트' 카테고리의 다른 글
Javascript Regular Expression Validator (0) | 2011.07.09 |
---|---|
마우스 오른쪽 버튼 및 F5 버튼 막는법 (0) | 2010.07.12 |
showModalDialog 사용법 (0) | 2010.03.14 |
[펌]자바에서 JSON parsing (1) | 2010.03.04 |
firefox javscript shell (0) | 2009.09.28 |