public synchronized boolean serialization(JSONObject response) throws JSONException { // 01. 清空原来容器 if (m_departments != null && m_departments.size() != 0) { m_departments.clear(); } // 02. http is ok m_Status = response.getInt(ProtocalConfig.HTTP_STATUS); if (!LogicalUtil.IsHttpSuccess(m_Status)) { String errorMsg = response.getString(ProtocalConfig.HTTP_ERROR_MSG); throw new JsonSerializationException(errorMsg); } // 03. 序列化json JSONArray jsonArray = response.getJSONArray(DepartmentListConfig.LIST); if (jsonArray == null) { throw new JsonSerializationException( NET_ERROR_JSON_SERILIZATION + ":" + DepartmentListConfig.LIST); } JSONObject jsonObject = null; DDepartment department = null; for (int index = 0; index < jsonArray.length(); index++) { jsonObject = (JSONObject) jsonArray.get(index); department = new DDepartment(); department.serialization(jsonObject); m_departments.add(department); } return true; }
public synchronized DDepartment getDepartmentByID(int id) { for (DDepartment department : m_departments) { if (department.getID() == id) return department; } return null; }