final String json = "[{\"id\":\"키즈베어\",\"tel\":\"010-1111-2222\"}," +
"{\"id\":\"김꽃드래\",\"tel\":\"010-3333-4444\"}," +
"{\"id\":\"민식이냐\",\"tel\":\"010-5555-6666\"}]" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button)findViewById(R.id.btn);
result = (TextView)findViewById(R.id.result);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
jsonParser();
}
});
}
private void jsonParser(){
String resultStr = "";
try {
//JSON String으로 부터 JSONArray 생성. [](대괄호)
JSONArray jArr = new JSONArray(json);
for (int i = 0; i < jArr.length(); i++) {
//JSONArray에서 i번째 해당하는 JSONObject를 추출.
JSONObject jObj = jArr.getJSONObject(i);
//각 이름("id"/"tel")에 해당하는 값을 추출.
resultStr += String.format("아이디 : %s 전화번호 : %s\n",
jObj.getString("id"), jObj.getString("tel"));
}
result.setText(resultStr);
} catch (JSONException e) {
Toast.makeText(JSONActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
"{\"id\":\"김꽃드래\",\"tel\":\"010-3333-4444\"}," +
"{\"id\":\"민식이냐\",\"tel\":\"010-5555-6666\"}]" ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button)findViewById(R.id.btn);
result = (TextView)findViewById(R.id.result);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
jsonParser();
}
});
}
private void jsonParser(){
String resultStr = "";
try {
//JSON String으로 부터 JSONArray 생성. [](대괄호)
JSONArray jArr = new JSONArray(json);
for (int i = 0; i < jArr.length(); i++) {
//JSONArray에서 i번째 해당하는 JSONObject를 추출.
JSONObject jObj = jArr.getJSONObject(i);
//각 이름("id"/"tel")에 해당하는 값을 추출.
resultStr += String.format("아이디 : %s 전화번호 : %s\n",
jObj.getString("id"), jObj.getString("tel"));
}
result.setText(resultStr);
} catch (JSONException e) {
Toast.makeText(JSONActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
[출처] [안드로이드 개발 강좌] JSON 파서|작성자 키즈베어
게시글 목록
| 번호 | 제목 |
|---|---|
| 10762 |
jQuery
회사에 히스토리에 써먹을 만한 자료
8
|
| 10754 | |
| 10752 |
MySQL
고수님들 도와주세요!
1
|
| 10749 |
Mobile
json 파싱방법
2
현재글
|
| 10746 | |
| 10740 | |
| 10738 | |
| 10736 | |
| 10733 |
JavaScript
주민번호, 외국인번호 검사 스크립트
2
|
| 10731 |
Mobile
Base64.java 파일입니다.
1
|
| 10730 | |
| 10727 | |
| 10725 |
MySQL
Mysql Text필드
1
|
| 10721 | |
| 10719 |
Mobile
[안드로이드] 프리퍼런스 사용 방법
1
|
| 10718 | |
| 10712 | |
| 10711 |
Mobile
[ios]사진촬영후 이미지 편집 샘플입니다.
|
| 10710 |
JavaScript
Html , javascript , css 강좌 사이트 입니다.
|
| 10709 |
JavaScript
주민번호 자바스크립트 체크
|
| 10707 |
jQuery
안녕하세요 jquery에 대해 물어볼게있습니다
1
|
| 10706 | |
| 20108 | |
| 10705 |
Mobile
[안드로이드] 자신의 폰에 깔려있는 앱들 검색하기
|
| 10703 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기