본문 바로가기

개발하자/ajax&json

object타입을 변수에 담아 변수 활용하기 $.toJSON(array)

 

jquery.json-2.3.js

 

파일을 WebContent에 넣는다

 

 

 

 

<%@ page language="java" contentType="text/html; charset=EUC-

KR"
 pageEncoding="EUC-KR"%>
<html>
<head>
<style type="text/css">
 #box1 { border:1px solid green; }
 #box2 { border:1px solid orange; }
</style>
<meta http-equiv="Content-Type" content="text/html;

charset=EUC-KR">
<title>Insert title here</title>
 <script

src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.mi

n.js"></script>
 <script src="js/jquery.json-2.3.js"></script>
 <script type="text/javascript">
 $(document).ready(function(){
 var member1=

{"id":"aa","pw":"bb","addr":"cc","tel":"dd"};
 var member2=

{"id":"ee","pw":"ff","addr":"gg","tel":"hh"};
 var member3=

{"id":"ii","pw":"jj","addr":"kk","tel":"ll"};

 var array=[];
 array.push(member1);
 array.push(member2);
 array.push(member3);

 $("#box1").text(array.toString());
 $("#box2").text($.toJSON(array));
 });
 </script>
</head>
<body>
 <div id="box1"></div><p>
 <div id="box2"></div>
</body>
</html>