Back to project page UTHPortal-Android-Gradle.
The source code is released under:
MIT License
If you think the Android project UTHPortal-Android-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uth.uthportal.buffers; // ww w . j ava 2s .c om import android.util.Log; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.uth.uthportal.collections.GeneralAnnouncement; /** * Parser for the general department announcements. * @author George T. Gougoudis * */ public class GeneralAnnParser { public Boolean wasSuccessful=true;//stays true if not changed public String errorMessage; public List<GeneralAnnouncement> parseGeneralAnnouncements(String JSONBuffer){ JSONObject jObj; try { jObj = new JSONObject(JSONBuffer); JSONArray announcements = jObj.getJSONArray("entries"); //Initialize list List<GeneralAnnouncement> generalAnnouncements = new ArrayList<GeneralAnnouncement>(); for (int i=0; i < announcements.length(); i++){ JSONObject announcement = announcements.getJSONObject(i);//get current object Date date = parseDateString( announcement.getString("date") ); String title = announcement.getString("title"); String link = announcement.getString("link"); String html = announcement.getString("html"); if (date == null) return null; generalAnnouncements.add(new GeneralAnnouncement(title, link, date, html)); } return generalAnnouncements; } catch (JSONException e) { wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.gap.parseGeneralAnnouncements:", errorMessage); } catch (NullPointerException e) { wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.gap.parseGeneralAnnouncements:", errorMessage); } return null; } private Date parseDateString(String dateStr){ //function to parse IsoDate SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date result; try { result = format.parse(dateStr); } catch (ParseException e) { wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.gap.parseDateString",errorMessage); return null; } return result; } }