jquery에서 json 데이터 읽기

each를 이용한 json data 읽기

jQuery.each( collection, callback(indexInArray, valueOfElement) )

or

$.each( collection, callback(indexInArray, valueOfElement) )

collection : array or object

callback = function

indexInArray : array 나 object 의 key

valueOfElement : array 나 object의 value

json 데이타를 jQuery에서 읽어오는 예제

<!doctype html>

<html lang="en">

<head>
  <meta charset="utf-8">
  <title>json 데이타를 jQuery에서 읽어오는 예제</title>
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>

<body>
  <script>
      var obj = {
          one: 1,
          two: 2,
          three: 3,
          four: 4,
          five: 5
      };

      $.each(obj, function(key, value) {
          alert('key:' + key + ', value:' + value);
      });

      //여러개의 데이타가 있을경우
      var obj2 = [{
          name: "홍길동",
          age: "20"
      }, {
          name: "이순신",
          age: "30"
      }];

      $.each(obj2, function(key, value) {
          alert('key:' + key + ', name:' + value.name + ',age:' + value.age);
      });

  </script>

</body>

</html>


'jquery' 카테고리의 다른 글

<tr>에서 get value() 벨류값 가져오기  (0) 2019.05.22
jQuery 선택자  (0) 2018.10.14
제이쿼리 소개  (0) 2018.10.14
jquery selector 선택자  (0) 2018.10.14

+ Recent posts