메뉴 건너뛰기

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

JSON(JavaScript Object Notation)

- Key와 Value로 구성
- []를 사용하여 배열형 Value 사용 가능
- JSON 공식 사이트 -
http://json.org/ 
 


"새 항목 추가"로 "Html" 형식의 파일인 [jQuery.getJSON.htm]과 "JScript" 형식의 파일인 [jQuery.getJSON.js]를 만들고 각각 코드를 아래와 같이 작성한다.




[jQuery.getJSON.htm]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>비동기적으로 JSON파일 로드</title>

    <script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            $("#btn .btnLoad").click(function() {

                $.getJSON("02.jQuery.getJSON.js", function(data) {

                    $('#pnlDisplay').empty(); // 패널(div)의 내용 초기화

                    var table = "<table border='1'><tr><td>인덱스</td><td>번호</td><td>이름</td></tr>";

                    // data를 탐색 : each() 메서드를 사용해서 데이터가 있는만큼 반복

                    $.each(data, function(index, entry) {

                        table += '<tr>';

                        table += '<td>' + index + '</td>';

                        table += '<td>' + entry["Num"] + '</td>';

                        if (entry["Name"]) { // 특정 필드를 비교할 때 이러한 표현법 사용

                            table += '<td>' + entry["Name"] + '</td>';

                        }

                        table += '</tr>';

                    });

                    table += "</table>";

                    $('#pnlDisplay').append(table); // 패널에 추가하기

                });

            });

        });   

    </script>       

</head>

<body>

    <div id="btn"><div class="btnLoad">HTML읽어오기</div></div>

    <div id="pnlDisplay">

    </div>

</body>

</html>

 



-------------------------------------------------------------------------------------




[jQuery.getJSON.js]


[

    {

        "Num": "1",

        "Name": "홍길동"

    },

    {

        "Num": "2",

        "Name": "백두산"

    },

    {

        "Num": "3",

        "Name": "한라산"

    }

]

 


-------------------------------------------------------------------------------------

 


[실행결과]

--> 첫 화면. 아래그림에서 'HTML읽어오기'텍스트를 마우스로 클릭하면...





--> 아래그림과 같이 'HTML읽어오기'텍스트 아래에 테이블이 출력된다.



List of Articles
번호 제목 날짜 조회 수
137 안드로이드 - setContentView()와 레이아웃 전개자(LayoutInflater) 2021.04.01 227
136 안드로이드 - Serializable를 활용한 다른 액티비티에 객체(Object) 전달하기 file 2021.03.31 281
135 안드로이드 - RecyclerView의 ViewType 구분하기 file 2021.04.02 931
134 안드로이드 - RecyclerView 안에 RecyclerView 구현하기 file 2021.04.02 502
133 안드로이드 - RatingBar를 통해 별점주기 file 2021.04.02 848
132 안드로이드 - KeyEvent(키 이벤트) 처리 file 2021.04.02 1213
131 안드로이드 - Json 파싱하기 file 2021.04.02 851
130 안드로이드 - BottomNavigationView 사용하여 하단 메뉴 만들기 file 2021.04.02 1439
129 안드로이드 - AsyncTask 구현 예제 file 2021.04.01 280
128 안드로이드 - AlertDialog 사용하여 알림창 띄우는 방법 총정리 file 2021.03.31 689
127 안드로이드 ( Android ) APK 파일 생성하기 file 2015.07.17 7309
126 실행중인 Service 확인하기 2014.08.28 6595
125 스토리보드 짜는 방법 file 2015.07.16 15419
124 서비스가 실행중인지 알아보는 방법 2015.07.16 6553
123 서버에서 이미지 불러와서 이미지뷰에 띄우기 file 2015.07.16 9842
122 사진찍기 및 앨범 에서 사진 가져오기!!! 2014.08.28 13889
121 사용자 정의 팝업창 띄우기 2015.07.16 6337
120 블루투스(Bluetooth) 통신에 대해 알아보자 file 2015.07.26 14048
119 블루투스(Bluetooth) 통신에 대해 알아보자 file 2015.07.01 7983
118 블루투스 및 비콘 관련 정리 2015.07.26 10828
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved