반응형
아래와 같이 예외처리를 하지 않으면, 다음과 같은
unhandled exception org.json.jsonexception
에러가 난다.
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | try { JSONObject obj = new JSONObject(data); JSONArray ja = obj.getJSONArray( "d" ); for ( int i = 0 ; i < ja.length(); i++) { JSONObject jsonData = ja.getJSONObject(i); CommonData cData = new CommonData(); cData.setCode(jsonData.getString( "Code" )); cData.setCodeName(jsonData.getString( "CodeName" )); cData.setHighCode(jsonData.getString( "HighCode" )); cData.setEtc1(jsonData.getString( "Etc1" )); cData.setEtc2(jsonData.getString( "Etc2" )); cData.setEtc3(jsonData.getString( "Etc3" )); cData.setEtc4(jsonData.getString( "Etc4" )); cData.setEtc5(jsonData.getString( "Etc5" )); arrCom.add(cData); } } catch (JSONException e) { tvOutput.setText(e.getMessage()); } |
반응형
'Android' 카테고리의 다른 글
error: Can't create handler inside thread that has not called Looper.prepare() (0) | 2019.09.28 |
---|---|
폰의 전화번호 조회 (0) | 2019.09.26 |
Android Exception Message (0) | 2019.09.05 |
Activity 간 이동 후에 이전 Activity로 되돌아 갈 때 (0) | 2019.09.05 |
Activity 간에 데이터 주고 받기 (0) | 2019.09.05 |
댓글