@Override protected Void doInBackground(Void... arg0) { // Creating service handler class instance ServiceHandler sh = new ServiceHandler(); // Making a request to url and getting response String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET); Log.d("Response: ", "> " + jsonStr); if (jsonStr != null) { try { JSONObject jsonObj = new JSONObject(jsonStr); // Getting JSON Array node contacts = jsonObj.getJSONArray(TAG_ITEMS); // looping through All Contacts for (int i = 0; i < contacts.length(); i++) { JSONObject c = contacts.getJSONObject(i); String teaser = c.getString(TAG_TEASER); String title = c.getString(TAG_TITLE); String date = c.getString(TAG_DATE); // tmp hashmap for single contact HashMap<string,> contact = new HashMap<string,>(); // adding each child node to HashMap key => value contact.put(TAG_TEASER, teaser); contact.put(TAG_TITLE, title); contact.put(TAG_DATE, date); // // adding contact to contact list contactList.add(contact); } } catch (JSONException e) { e.printStackTrace(); } } else { Log.e("ServiceHandler", "Couldn't get any data from the url"); } return null; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)