ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • JSONObject
    Search: Android Android 2021. 10. 26. 19:40

    사용 방법 예제

    try {
    	JSONObject jo = new JSONObject(response);
    	String id = jo.getString("id");
    } catch (JSONException e) {
    	//...
    }

    JSONObject생성은 try catch문 안에 사용해야 한다.

     

    Volley에 적용한 Ex

    Response.Listener<String> rplsn = new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            ((TextView)findViewById(R.id.textview1)).setText(response.toString());
            try {
                JSONObject jo = new JSONObject(response);
                ((TextView)findViewById(R.id.textview2)).setText(jo.getString("id"));
            } catch (JSONException e) {
                Toast.makeText(getApplicationContext(), "Err onResponseJson: " + e.toString(), Toast.LENGTH_LONG).show();
            }
        }
    };

     

     

    'Android' 카테고리의 다른 글

    TextView  (0) 2022.07.28
    알림접근허용  (0) 2022.07.19
    Application.dataPath  (0) 2021.11.03
    Volley  (0) 2021.10.26
    Android 삭제된 연락처 복원  (0) 2021.05.18
    Android App 이름  (1) 2021.03.09
    Android logcat Log 종류  (0) 2021.03.08
    Android adb logcat 명령어  (0) 2021.03.08

    댓글