Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ArrayList<HashMap<String, String>> ParseJSON(String json) {
- if (json != null) {
- try {
- // Hashmap for ListView
- ArrayList<HashMap<String, String>> studentList = new ArrayList<HashMap<String, String>>();
- JSONObject jsonObj = new JSONObject(json);
- // Getting JSON Array node
- JSONArray students = jsonObj.getJSONArray(TAG_STUDENTINFO);
- // looping through All Students
- for (int i = 0; i < students.length(); i++) {
- JSONObject c = students.getJSONObject(i);
- String id = c.getString(TAG_ID);
- String name = c.getString(TAG_NAME);
- String email = c.getString(TAG_EMAIL);
- String address = c.getString(TAG_ADDRESS);
- String gender = c.getString(TAG_GENDER);
- // Phone node is JSON Object
- JSONObject phone = c.getJSONObject(TAG_PHONE);
- String mobile = phone.getString(TAG_PHONE_MOBILE);
- String home = phone.getString(TAG_PHONE_HOME);
- // tmp hashmap for single student
- HashMap<String, String> student = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- student.put(TAG_ID, id);
- student.put(TAG_NAME, name);
- student.put(TAG_EMAIL, email);
- student.put(TAG_PHONE_MOBILE, mobile);
- // adding student to students list
- studentList.add(student);
- }
- return studentList;
- } catch (JSONException e) {
- e.printStackTrace();
- return null;
- }
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- return null;
- }
- }
Add Comment
Please, Sign In to add comment