ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>JSON ์„ ์ด์šฉํ•œ ๊ฐ์ฒด์ƒ์„ฑ</title>

<script type="text/javascript">

 //:::::::::::::::::::::: ๋ฐฉ๋ฒ• 1 ::::::::::::::::::::::
 var stu = {
  name  : "ํ™๊ธธ๋™",
  school  : "ํ•˜๋ฒ„๋“œ๋†๋Œ€",
  subject : "์”จ์•—์žฌ๋ฐฐ",
  grade : 3,
  friends :[
        {name : "๋ฐ•์žฌ๋ฒ”"},
        {name : "๋‹ˆ์ด์ฟค"},
        {name : "์žฅ์šฐ์˜"}
       ],

     toString : function() {
   var txt =
    "์ด๋ฆ„์€ " + stu.name + "์ด๊ณ  <br/> " +
    "ํ•™๊ต๋Š” " + stu.school + "์ด๋‹ค <br/> " +
    "๊ทธ์˜ ๊ณผ๋ชฉ์€  " + stu.subject + " <br/> " +
    "ํ•™๋…„์€ " + stu.grade + "<br/> " +
    "์นœ๊ตฌ๋Š” ";

    for(i in this.friends) {
     txt += this.friends[i].name;
     if(i != this.friends.length-1) {
      txt += ", ";
     }
    }

    txt += "์ด(๊ฐ€) ์žˆ๋‹ค";
    return txt;
   
     }
 };

 document.write ( stu.toString() );

 //:::::::::::::::::::::: ๋ฐฉ๋ฒ• 2 ::::::::::::::::::::::

 //var tmp;
 //tmp = "";
 
 //for(i = 0; i < stu.friends.length ; i++) {
 // tmp = tmp + stu.friends[i].name + ", ";
 //}

 /*
 document.write(
  "์ด๋ฆ„์€ " + stu.name + "์ด๊ณ  <br/> " +
  "ํ•™๊ต๋Š” " + stu.school + "์ด๋‹ค <br/> " +
  "๊ทธ์˜ ๊ณผ๋ชฉ์€  " + stu.subject + " <br/> " +
  "ํ•™๋…„์€ " + stu.grade + "<br/> " +
  "์นœ๊ตฌ๋“ค์€ " + tmp + " ์ด ์žˆ๋‹ค. "
 );
 */
</script>

</head>
<body>

</body>
</html>

๋Œ“๊ธ€