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 파서|작성자 키즈베어
게시글 목록
| 번호 | 제목 |
|---|---|
| 11208 |
JavaScript
글자 깜박임 blink 익스에서 구현
3
|
| 11205 | |
| 11202 | |
| 11198 |
JavaScript
select선택에따른추가select동적으로보여주기
3
|
| 11197 | |
| 17717 | |
| 11194 | |
| 11192 |
JavaScript
두 종류의 메뉴셋 사용시 메뉴선택 표시 문제
1
|
| 11190 | |
| 17708 | |
| 20659 | |
| 20653 | |
| 17702 |
견적서
견적서의뢰 ....
5
|
| 17693 | |
| 11186 | |
| 20649 | |
| 11184 | |
| 11179 | |
| 11177 | |
| 11176 |
JavaScript
도와주세요~
|
| 20648 | |
| 20643 | |
| 20639 | |
| 11175 |
JavaScript
자바스크립트 입문자인데..이미지 변경 스크립트..좀 도와주세여
|
| 11167 |
jQuery
list sort에 좋은것
7
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기