안녕하세요.
현재 apache 웹서버로 mysql, php를 돌리면서 안드로이드 단으로 데이터를 가져오고
안드로이드 단에서 도로 데이터를 삽입하는 것을 구현하고 있는데요,
php에 데이터를 빼오는 것 까지는 잘 되고 있습니다.
{"results":[{"email":"vlwldnr@naver.com", "name":"jiwook"},{"email":"doyeon", "name":"doyeon"},{"email":"hyesung", "name":"hyesung"},{"email":"haewon", "name":"haewon"}]}
위와 같은 형식으로 JSONObject 내에 JSONArray로 받아오고 JSONArray는 또 JSONObject로 구성되어 있는데요,
private JSONArray user = null;
private ArrayList<HashMap<String, String>> userList;
메인 클래스에
private JSONArray user = null;
private ArrayList<HashMap<String, String>> userList;
와 같이 JSONArray와 ArrayList<HashMap>을 선언하고
클래스 내에 아래와 같이 별도의 메소드를 하나 만들어
public void updateJSONdata(){
userList = new ArrayList<HashMap<String, String>>();
// Bro, it's time to power up the J parser
JSONParser jParser = new JSONParser();
// Feed the beast our comments url, and it spits us
// back a JSON object. Boo-yeah Jerome.
JSONObject json = jParser.getJSONFromUrl(READ_USER_URL);
// when parsing JSON stuff, we should probably
// try to catch any exceptions:
try {
//JSONObject result = json.getJSONObject(TAG_OBJECT);
user = json.getJSONArray(TAG_RESULT);
// looping through all posts according to the json object returned
for (int i = 0; i < user.length(); i++) {
JSONObject c = user.getJSONObject(i);
// gets the content of each tag
String email = c.getString(TAG_EMAIL);
String name = c.getString(TAG_USERNAME);
//String username = c.getString(TAG_USERNAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_EMAIL, email);
map.put(TAG_USERNAME, name);
// adding HashList to ArrayList
userList.add(map);
// annndddd, our JSON data is up to date same with our array
// list
}
} catch (JSONException e) {
e.printStackTrace();
}
아래와 같이 해당 클래스가 실행되면 위와 같은 메소드를 실행하게 해 뒀는데요,
public class LoadMember extends AsyncTask<Void, Void, Boolean> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ReadComments.this);
pDialog.setMessage("Loading Member...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Boolean doInBackground(Void... arg0) {
updateJSONdata();
return null;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
pDialog.dismiss();
updateList();
}
}
LogCat에 에러 메시지가 뜨지 않는데
정작 목록에는 아무것도 뜨지를 않네요...
데이터가 userList에 HashMap 형태로 잘 들어갔는지 확인할 수 있는 방법이 있을까요?
답변에 미리 감사드립니다.