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; /*from www. ja v a 2s . c o m*/ import android.util.Log; import com.uth.uthportal.collections.AvailableCourse; import com.uth.uthportal.collections.CourseInfo; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; /** * Created by Giorgos T. Gougoudis on 9/7/2014. * Available courses parser. */ public class AvailableCoursesParser { public Boolean wasSuccessful=true;//stays true if not changed public String errorMessage; public AvailableCoursesParser(){ } public List<AvailableCourse> parseAvailableCourses(String JSONBuffer){ JSONArray jArr; List<AvailableCourse> availableCourseList = new ArrayList<AvailableCourse>(); try { JSONObject jObj = new JSONObject(JSONBuffer); jArr= jObj.getJSONArray("children"); } catch (JSONException e) { wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.acp.AvailableCourses:",errorMessage); return null; } for(int i = 0; i < jArr.length(); i++){ JSONObject avCourseObj; try{ avCourseObj = jArr.getJSONObject(i); availableCourseList.add( parseAvailableCourse(avCourseObj)); } catch(JSONException e){ wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.acp.AvailableCourses:",errorMessage); return null; } catch (NullPointerException e) { wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.acp.AvailableCourses:",errorMessage); return null; } } return availableCourseList; } private AvailableCourse parseAvailableCourse(JSONObject avCourse){ CourseInfo cInfo; String code; JSONObject cInfoObj; try{ code = avCourse.getString("code"); cInfoObj = avCourse.getJSONObject("info"); cInfo = parseAvailCourseInfo(cInfoObj); } catch(JSONException e){ wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.acp.AvailableCourse:",errorMessage); return null; } if (cInfo == null) return null; return new AvailableCourse(code, cInfo, false); } private CourseInfo parseAvailCourseInfo(JSONObject cInfoObj){ String name; String link; try{ name = cInfoObj.getString("name"); link = cInfoObj.getString("link"); } catch(JSONException e){ wasSuccessful = false; errorMessage = e.getMessage(); Log.e("e.acp.AvailableCourseInfo:",errorMessage); return null; } return new CourseInfo(name, link); } }