@Override protected Void doInBackground(Void... arg0) { ServiceHandler sh = new ServiceHandler(); String jsonStr = sh.makeServiceCall(checkoutUrl, ServiceHandler.GET); Log.d("Response", "<" + jsonStr); if (jsonStr != null) { try { JSONObject jsonObj = new JSONObject(jsonStr); String err = jsonObj.getString("error"); String msg = jsonObj.getString("msg"); Log.d("err", err); if (err.equals("false")) { flag = 1; } } catch (JSONException e) { e.printStackTrace(); } } else { Log.e("ServiceHandler", "Could not get data"); } return null; }
@Override protected Void doInBackground(Void... arg0) { // Creating service handler class that we made for http requests ServiceHandler sh = new ServiceHandler(); String jsonStr = sh.makeServiceCall(url_flight, ServiceHandler.GET); Log.d("Response: ", "> " + jsonStr); beerList = beerTypes.randomFlight(jsonStr); return null; }
@Override protected Void doInBackground(Void... arg0) { // Creating service handler class instance ServiceHandler mServiceHandler = new ServiceHandler(); // Making a request to url and getting response String jsonStr = mServiceHandler.makeServiceCall(url, ServiceHandler.GET); Log.d("Response: ", "> " + jsonStr); if (jsonStr != null) { try { names = new ArrayList<String>(); JSONObject jsonObj = new JSONObject(jsonStr); // Getting JSON Array node allBooksJSON = jsonObj.getJSONArray(TAG_BOOKS); // looping through All Contacts for (int i = 0; i < allBooksJSON.length(); i++) { JSONObject c = allBooksJSON.getJSONObject(i); String name = c.getString(TAG_NAME); names.add(name); String aut = c.getString(TAG_AUT); String year = c.getString(TAG_YEAR); String imgname = c.getString(TAG_IMG); // tmp hashmap for single contact HashMap<String, String> oneRecord = new HashMap<String, String>(); // adding each child node to HashMap key => value oneRecord.put(TAG_NAME, name); oneRecord.put(TAG_AUT, aut); oneRecord.put(TAG_YEAR, year); oneRecord.put(TAG_IMG, imgname); // adding contact to contact list bookList.add(oneRecord); } } catch (JSONException e) { e.printStackTrace(); } } else { Log.e("ServiceHandler", "Couldn't get any data from the url"); } return null; }