티스토리 뷰

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

var x = '["홍길동", "이순신", "유관순"]';

//객체로 바꿔줘야함

var obj = jQuery.parseJSON(x);

for( var x in obj){

console.log(obj[x]);

}

var y = '{"name":"홍길동","age":"20","address":"서울"}';

var obj2 = jQuery.parseJSON(y);

for( var c in obj2){

console.log(obj2[c]);

}

});

</script>

</head>

<body>

<ul>

<li>1</li>

<li>2</li>

<li>3</li>

<li>4</li>

<li>5</li>

</ul>

</body>

</html>

댓글