메뉴 건너뛰기

?

단축키

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
번호 제목 날짜 조회 수
37 안드로이드 - AlertDialog 사용하여 알림창 띄우는 방법 총정리 file 2021.03.31 690
36 안드로이드 - setContentView()와 레이아웃 전개자(LayoutInflater) 2021.04.01 227
35 안드로이드 - 날짜 및 시간 정보 입력받기 (DatePickerDialog / TimePickerDialog) file 2021.04.01 1772
34 안드로이드 - 명시적 인텐트(Explicit Intent)와 암시적 인텐트 (Implicit Intent) file 2021.04.01 324
33 안드로이드 - 옵션 메뉴 (Option Menu) 구현 방법 file 2021.04.01 283
32 안드로이드 - 컨텍스트 메뉴(Context Menu) 사용 예제 file 2021.04.01 207
31 안드로이드 - 리스트뷰(ListView) 구현 file 2021.04.01 490
30 안드로이드 - 액티비티(Activity)와 액티비티 생명 주기(Activity Life Cycle) file 2021.04.01 225
29 안드로이드 - AsyncTask 구현 예제 file 2021.04.01 280
28 안드로이드 - 프로그레스바(ProgressBar) 구현하기 file 2021.04.01 451
27 안드로이드 - 툴바(ToolBar)를 사용하여 앱바(App Bar) 구현하기 file 2021.04.01 455
26 안드로이드 - 네비게이션 드로어(Navigation Drawer)를 활용하여 슬라이드 메뉴 구현하기 file 2021.04.01 1865
25 안드로이드 - 리사이클러 뷰(RecyclerView) 구현 file 2021.04.01 390
24 안드로이드 - SQLiteDatabase 구현하기 file 2021.04.01 249
23 안드로이드 - 타이머(Timer) 구현하기 2021.04.01 1369
22 안드로이드 - Json 파싱하기 file 2021.04.02 851
21 안드로이드 - RecyclerView 안에 RecyclerView 구현하기 file 2021.04.02 502
20 안드로이드 - 뷰페이저(ViewPager) 구현 file 2021.04.02 323
19 안드로이드 - SharedPreferences에 앱 정보 저장하기 file 2021.04.02 395
18 안드로이드 - RatingBar를 통해 별점주기 file 2021.04.02 850
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved