ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • json의 기본형 test
    카테고리 없음 2018. 6. 9. 07:23

    json의 기본형 던지고 읽어오기.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     private void test() {
            String temp = "{\"page\":\"1\",\"content\":[{\"num\":\"110294\",\"title\":\"안녕하세요 가입했어요\",\"writer\":\"jinsil\"},{\"num\":\"241253\",\"title\":\"저도 가입했어요\",\"writer\":\"a\"}]}";
            try {
                JSONObject jsonObject = new JSONObject(temp);
                String page = jsonObject.getString("page");
                Log.d("heu""page: " + page);
                JSONArray jArr = jsonObject.getJSONArray("content");
     
                for (int i = 0; i < jArr.length(); i++) {
                    JSONObject tempobj = jArr.getJSONObject(i);
                    String num = tempobj.getString("num");
                    String title = tempobj.getString("title");
                    String writer = tempobj.getString("writer");
                    Log.d("heu""num:" + num + ", title: " + title + ", writer: " + writer);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    cs


    반응형

    댓글

Designed by Tistory.