Example usage for org.json JSONObject getJSONObject

List of usage examples for org.json JSONObject getJSONObject

Introduction

In this page you can find the example usage for org.json JSONObject getJSONObject.

Prototype

public JSONObject getJSONObject(String key) throws JSONException 

Source Link

Document

Get the JSONObject value associated with a key.

Usage

From source file:org.eclipse.orion.server.tests.servlets.git.GitDiffTest.java

@Test
public void testDiffUntrackedUri() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());

    String projectName = getMethodName();
    JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString());

    String fileName = "new.txt";
    WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

    JSONObject newTxt = getChild(project, "new.txt");

    String gitDiffUri = newTxt.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_DIFF);

    request = getGetRequest(gitDiffUri + "?parts=uris");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // modified assertDiffUris(...);
    JSONObject jsonPart = new JSONObject(response.getText());
    assertEquals(Diff.TYPE, jsonPart.getString(ProtocolConstants.KEY_TYPE));

    String fileOldUri = jsonPart.getString(GitConstants.KEY_COMMIT_OLD);
    request = getGetRequest(fileOldUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());

    String fileNewUri = jsonPart.getString(GitConstants.KEY_COMMIT_NEW);
    request = getGetRequest(fileNewUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals("", response.getText());

    String fileBaseUri = jsonPart.getString(GitConstants.KEY_COMMIT_BASE);
    request = getGetRequest(fileBaseUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());

    assertEquals(gitDiffUri, jsonPart.getString(ProtocolConstants.KEY_LOCATION));
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitDiffTest.java

@Test
public void testDiffWithCommonAncestor() throws Exception {
    // clone: create
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
    String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

    // get project metadata
    WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());

    String branchName = "dev";
    response = branch(branchesLocation, branchName);
    assertEquals(branchName, new JSONObject(response.getText()).getString(ProtocolConstants.KEY_NAME));

    checkoutBranch(cloneLocation, branchName);

    // modify while on 'dev'
    JSONObject testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "change in dev");

    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    // "git add ."
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // commit all
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on dev", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // assert clean
    assertStatus(StatusResult.CLEAN, gitStatusUri);

    // checkout 'master'
    checkoutBranch(cloneLocation, Constants.MASTER);

    // modify the same file on master
    request = getPutFileRequest(clonePath.append("test.txt").toString(), "change in master");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
    gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS);
    gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

    // "git add ."
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // commit all
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit on master", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // assert clean
    assertStatus(StatusResult.CLEAN, gitStatusUri);

    String masterDiffLocation = findDiffLocationForBranchByName(branchesLocation, Constants.MASTER);
    String location = getDiffLocation(masterDiffLocation, branchName);
    // TODO: don't create URIs out of thin air
    location += "test.txt";

    request = getGetRequest(location + "?parts=uris,diff");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    String[] parts = parseMultiPartResponse(response);

    assertDiffUris(location, new String[] { "change in master", "change in dev", "test" },
            new JSONObject(parts[0]));
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitDiffTest.java

private String getDiffCachedLocation(JSONObject fileObject) throws JSONException, IOException, SAXException {
    // cannot get status on a file

    // request the status on parent
    String fileLocation = fileObject.getString(ProtocolConstants.KEY_LOCATION);
    WebRequest request = getGetRequest(fileLocation + "?parts=meta");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject fileMetaObject = new JSONObject(response.getText());
    JSONArray parents = fileMetaObject.getJSONArray(ProtocolConstants.KEY_PARENTS);
    JSONObject parentObject = parents.getJSONObject(0);

    request = getGetRequest(parentObject.getString(ProtocolConstants.KEY_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    parentObject = new JSONObject(response.getText());

    request = getGetGitStatusRequest(/*from ww  w  .  j av a 2s.  c  om*/
            parentObject.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_STATUS));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject statusResponse = new JSONObject(response.getText());

    // find entry for the file
    JSONArray changed = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED);
    for (int i = 0; i < changed.length(); i++) {
        JSONObject changedEntry = changed.getJSONObject(i);
        if (changedEntry.getString(ProtocolConstants.KEY_NAME)
                .equals(fileObject.getString(ProtocolConstants.KEY_NAME))) {
            return changedEntry.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_DIFF);
        }
    }
    fail(NLS.bind("Diff Cached Location for {0}, could not be found",
            fileObject.getString(ProtocolConstants.KEY_NAME)));
    return null;
}

From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java

@Test
public void testEditEvent() throws Exception {
    File file = File.createTempFile("hob", ".ics");
    try {/*from  ww w . j  ava  2 s.c  o m*/
        String ical = "BEGIN:VCALENDAR\n" + "PRODID:-//Whizzo Software//Hobson 1.0//EN\n" + "VERSION:2.0\n"
                + "BEGIN:VEVENT\n" + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20130714T170000Z\n"
                + "DTEND:20130714T170000Z\n" + "SUMMARY:My Task\n"
                + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Action','properties':{'message':'foo'}}]\n"
                + "END:VEVENT\n" + "END:VCALENDAR";

        String ical2 = "BEGIN:VCALENDAR\n" + "PRODID:-//Whizzo Software//Hobson 1.0//EN\n" + "VERSION:2.0\n"
                + "BEGIN:VEVENT\n" + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20130714T170000Z\n"
                + "DTEND:20130714T170000Z\n" + "SUMMARY:My Edited Task\n"
                + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Edited Action','properties':{'message':'foobar'}}]\n"
                + "END:VEVENT\n" + "END:VCALENDAR";

        // write out ICS to temp file
        FileWriter fw = new FileWriter(file);
        fw.append(ical);
        fw.close();

        ICalTaskProvider p = new ICalTaskProvider("pluginId", null, null,
                TimeZone.getTimeZone("America/Denver"));
        p.setScheduleExecutor(new MockScheduledTaskExecutor());
        p.setScheduleFile(file);
        p.start();

        // make sure the task was created
        assertEquals(1, p.getTasks().size());

        // create task JSON
        JSONObject json = new JSONObject();
        json.put("name", "My Edited Task");
        JSONArray conds = new JSONArray();
        json.put("conditions", conds);
        JSONObject cond = new JSONObject();
        conds.put(cond);
        cond.put("start", "20130714T170000Z");
        JSONArray actions = new JSONArray();
        json.put("actions", actions);
        JSONObject action = new JSONObject();
        actions.put(action);
        action.put("pluginId", "com.whizzosoftware.hobson.server-api");
        action.put("actionId", "log");
        action.put("name", "My Edited Action");
        JSONObject props = new JSONObject();
        action.put("properties", props);
        props.put("message", "foobar");

        // update the task
        p.updateTask("15dee4fe-a841-4cf6-8d7f-76c3ad5492b1", json);

        assertTrue(file.exists());

        // read back file
        Calendar cal = new CalendarBuilder().build(new FileInputStream(file));
        assertEquals(1, cal.getComponents().size());
        VEvent c = (VEvent) cal.getComponents().get(0);
        assertEquals("My Edited Task", c.getProperty("SUMMARY").getValue());
        assertEquals("15dee4fe-a841-4cf6-8d7f-76c3ad5492b1", c.getProperty("UID").getValue());
        assertEquals("20130714T170000Z", c.getProperty("DTSTART").getValue());
        JSONArray aj = new JSONArray(new JSONTokener(c.getProperty("COMMENT").getValue()));
        assertEquals(1, aj.length());
        JSONObject cj = aj.getJSONObject(0);
        assertEquals("com.whizzosoftware.hobson.server-api", cj.getString("pluginId"));
        assertEquals("My Edited Action", cj.getString("name"));
        assertEquals("log", cj.getString("actionId"));
        assertTrue(cj.has("properties"));
        JSONObject pj = cj.getJSONObject("properties");
        assertEquals("foobar", pj.getString("message"));
    } finally {
        file.delete();
    }
}

From source file:com.github.irib_examples.Act_NetworkListView.java

private Response.Listener<JSONObject> createMyReqSuccessListener() {
    return new Response.Listener<JSONObject>() {
        @Override/* w  ww  .  java 2 s  . c  om*/
        public void onResponse(JSONObject response) {
            try {
                JSONObject feed = response.getJSONObject("feed");
                JSONArray entries = feed.getJSONArray("entry");
                JSONObject entry;
                for (int i = 0; i < entries.length(); i++) {
                    entry = entries.getJSONObject(i);

                    String url = null;

                    JSONObject media = entry.getJSONObject("media$group");
                    if (media != null && media.has("media$thumbnail")) {
                        JSONArray thumbs = media.getJSONArray("media$thumbnail");
                        if (thumbs != null && thumbs.length() > 0) {
                            url = thumbs.getJSONObject(0).getString("url");
                        }
                    }

                    mEntries.add(new PicasaEntry(entry.getJSONObject("title").getString("$t"), url));
                }
                mAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                showErrorDialog();
            }
        }
    };
}

From source file:ssc.SenseSmartCity.java

/** 
 * Take a response object and return response object. The response object is
 * the raw JSON data retrieved from SSC server. It contain a key and a value.
 * Here the value is assumed to be a object.
 * //from   w  w  w.  j  a  v  a 2 s.  c  om
 * @param data Raw JSON object from SSC server
 * 
 * @return A JSON object containing the requested data
 * 
 * @throws SSCException.MalformedData if data is not extractable 
 */
private JSONObject responseObject(String data) {

    JSONObject data_obj;

    try {

        JSONObject response = new JSONObject(data);
        data_obj = response.getJSONObject(SSCResources.Query.RESPONSE);

    } catch (org.json.JSONException e) {

        throw new SSCException.MalformedData(e);

    }

    return data_obj;

}

From source file:net.jmhertlein.mcanalytics.api.request.UniqueLoginsPerDayRequest.java

@Override
public Map<LocalDate, Integer> processResponse(JSONObject response) {
    JSONObject counts = response.getJSONObject("logins");
    LinkedHashMap<LocalDate, Integer> ret = new LinkedHashMap<>();
    for (String s : counts.keySet()) {
        ret.put(LocalDate.parse(s), counts.getInt(s));
    }//from   w  w  w  .  ja  v a 2 s  .  c o m

    return ret;
}

From source file:org.cvrgrid.waveform.backing.GlobusUploadBacking.java

/**
 * Private API that polls all the endpoints for a user.
 *///from  ww  w. j a  va2s  .c om
private Status getEndpoints(JSONTransferAPIClient client, String query, String endpointType) {

    try {

        JSONTransferAPIClient.Result r = client.getResult(query);
        Map<String, GlobusEndpointList> globusEndpointLists = this.getGlobusEndpointLists();
        GlobusEndpointList globusEndpointList = globusEndpointLists.get(endpointType);
        logger.info("Endpoint Listing " + query + " for " + client.getUsername() + ": ");
        Iterator<?> keys = r.document.keys();
        while (keys.hasNext()) {
            String next = (String) keys.next();
            if (next.equalsIgnoreCase("data_type")) {

                globusEndpointList.setDataType(r.document.getString(next));

            } else if (next.equalsIgnoreCase("length")) {

                globusEndpointList.setLength(new Integer(r.document.getString(next)));

            } else if (next.equalsIgnoreCase("limit")) {

                globusEndpointList.setLimit(r.document.getString(next));

            } else if (next.equalsIgnoreCase("offset")) {

                globusEndpointList.setOffset(r.document.getString(next));

            } else if (next.equalsIgnoreCase("total")) {

                globusEndpointList.setTotal(r.document.getString(next));

            } else if (next.equalsIgnoreCase("data")) {
                JSONArray data = r.document.getJSONArray(next);
                int size = data.length();
                ArrayList<GlobusEndpoint> globusEndpoints = new ArrayList<GlobusEndpoint>();
                for (int j = 0; j < size; j++) {
                    GlobusEndpoint globusEndpoint = new GlobusEndpoint();
                    JSONObject globusEndpointInfo = data.getJSONObject(j);
                    Iterator<?> keys2 = globusEndpointInfo.keys();
                    while (keys2.hasNext()) {
                        String next2 = (String) keys2.next();
                        if (next2.equalsIgnoreCase("data_type")) {

                            globusEndpoint.setDataType(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("username")) {

                            globusEndpoint.setUserName(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("globus_connect_setup_key")) {

                            globusEndpoint.setGlobusConnectSetupKey(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("name")) {

                            globusEndpoint.setName(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("activated")) {

                            globusEndpoint.setActivated(globusEndpointInfo.getBoolean(next2));

                        } else if (next2.equalsIgnoreCase("is_globus_connect")) {

                            globusEndpoint.setIsGlobusConnect(globusEndpointInfo.getBoolean(next2));

                        } else if (next2.equalsIgnoreCase("ls_link")) {

                            JSONObject linkInfo = globusEndpointInfo.getJSONObject(next2);
                            GlobusLink lsLink = new GlobusLink();
                            Iterator<?> keys3 = linkInfo.keys();
                            while (keys3.hasNext()) {

                                String next3 = (String) keys3.next();
                                if (next3.equalsIgnoreCase("data_type")) {

                                    lsLink.setDataType(linkInfo.getString(next3));

                                } else if (next3.equalsIgnoreCase("href")) {

                                    lsLink.setHref(linkInfo.getString(next3));

                                } else if (next3.equalsIgnoreCase("resource")) {

                                    lsLink.setResource(linkInfo.getString(next3));

                                } else if (next3.equalsIgnoreCase("relationship")) {

                                    lsLink.setRelationship(linkInfo.getString(next3));

                                } else if (next3.equalsIgnoreCase("title")) {

                                    lsLink.setTitle(linkInfo.getString(next3));

                                }

                            }
                            globusEndpoint.setLsLink(lsLink);

                        } else if (next2.equalsIgnoreCase("canonical_name")) {

                            globusEndpoint.setCanonicalName(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("myproxy_server")) {

                            globusEndpoint.setMyProxyServer(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("expire_time")) {

                            //globusEndpoint.setExpireTime(new Date(globusEndpointInfo.getString(next2)));

                        } else if (next2.equalsIgnoreCase("public")) {

                            globusEndpoint.setGlobusPublic(globusEndpointInfo.getBoolean(next2));

                        } else if (next2.equalsIgnoreCase("description")) {

                            globusEndpoint.setDescription(globusEndpointInfo.getString(next2));

                        } else if (next2.equalsIgnoreCase("data")) {

                            JSONArray serverData = globusEndpointInfo.getJSONArray(next2);
                            int serverDataSize = serverData.length();
                            ArrayList<GlobusServer> globusServers = new ArrayList<GlobusServer>();
                            for (int k = 0; k < serverDataSize; k++) {
                                GlobusServer globusServer = new GlobusServer();
                                JSONObject globusServerInfo = serverData.getJSONObject(k);
                                Iterator<?> keys4 = globusServerInfo.keys();
                                while (keys4.hasNext()) {
                                    String next4 = (String) keys4.next();
                                    if (next4.equalsIgnoreCase("data_type")) {

                                        globusServer.setDataType(globusServerInfo.getString(next4));

                                    } else if (next4.equalsIgnoreCase("id")) {

                                        globusServer.setId(globusServerInfo.getInt(next4));

                                    } else if (next4.equalsIgnoreCase("hostname")) {

                                        globusServer.setHostname(globusServerInfo.getString(next4));

                                    } else if (next4.equalsIgnoreCase("uri")) {

                                        globusServer.setUri(globusServerInfo.getString(next4));

                                    } else if (next4.equalsIgnoreCase("scheme")) {

                                        globusServer.setScheme(globusServerInfo.getString(next4));

                                    } else if (next4.equalsIgnoreCase("port")) {

                                        if (globusServerInfo.get("port").toString().equalsIgnoreCase("null")) {

                                            globusServer.setPort(0);

                                        } else {

                                            globusServer.setPort(globusServerInfo.getInt(next4));

                                        }

                                    } else if (next4.equalsIgnoreCase("subject")) {

                                        globusServer.setSubject(globusServerInfo.getString(next4));

                                    } else if (next4.equalsIgnoreCase("is_connected")) {

                                        globusServer.setIsConnected(globusServerInfo.getBoolean(next4));

                                    }

                                }
                                globusServers.add(globusServer);
                            }
                            globusEndpoint.setGlobusServers(globusServers);
                        }

                    }
                    globusEndpoints.add(globusEndpoint);
                }
                globusEndpointList.setGlobusEndpoints(globusEndpoints);
            }

        }

        globusEndpointLists.put(endpointType, globusEndpointList);
        this.setGlobusEndpointLists(globusEndpointLists);
        return Status.OK;

    } catch (Exception e) {

        logger.error("Got an exception..\n");
        logger.error(e.getMessage());
        logger.error(e.getStackTrace().toString());
        e.printStackTrace();
        return Status.FAIL;

    }

}

From source file:com.synox.android.providers.UsersAndGroupsSearchProvider.java

private Cursor searchForUsersOrGroups(Uri uri) {
    MatrixCursor response = null;/*from w  w  w.  java  2s  .com*/

    String userQuery = uri.getLastPathSegment().toLowerCase();

    /// need to trust on the AccountUtils to get the current account since the query in the client side is not
    /// directly started by our code, but from SearchView implementation
    Account account = AccountUtils.getCurrentOwnCloudAccount(getContext());

    /// request to the OC server about users and groups matching userQuery
    GetRemoteShareesOperation searchRequest = new GetRemoteShareesOperation(userQuery, REQUESTED_PAGE,
            RESULTS_PER_PAGE);
    RemoteOperationResult result = searchRequest.execute(account, getContext());
    List<JSONObject> names = new ArrayList<JSONObject>();
    if (result.isSuccess()) {
        for (Object o : result.getData()) {
            // Get JSonObjects from response
            names.add((JSONObject) o);
        }
    } else {
        showErrorMessage(result);
    }

    /// convert the responses from the OC server to the expected format
    if (names.size() > 0) {
        response = new MatrixCursor(COLUMNS);
        Iterator<JSONObject> namesIt = names.iterator();
        int count = 0;
        JSONObject item;
        String displayName;
        Uri dataUri;
        Uri userBaseUri = new Uri.Builder().scheme("content").authority(DATA_USER).build();
        Uri groupBaseUri = new Uri.Builder().scheme("content").authority(DATA_GROUP).build();
        try {
            while (namesIt.hasNext()) {
                item = namesIt.next();
                String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL);
                JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
                byte type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
                String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH);
                if (GetRemoteShareesOperation.GROUP_TYPE.equals(type)) {
                    displayName = getContext().getString(R.string.share_group_clarification, userName);
                    dataUri = Uri.withAppendedPath(groupBaseUri, shareWith);
                } else {
                    displayName = userName;
                    dataUri = Uri.withAppendedPath(userBaseUri, shareWith);
                }
                response.newRow().add(count++) // BaseColumns._ID
                        .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1
                        .add(dataUri);
            }
        } catch (JSONException e) {
            Log_OC.e(TAG, "Exception while parsing data of users/groups", e);
        }
    }

    return response;
}

From source file:dhbw.RaplaCalGenerator.HTMLCleaner.java

public ArrayList<Course> generateCourses(String location) {
    try {//from  w w  w.  j a v a 2s .co m

        head.add(html.indexOf("<head"));
        head.add(html.indexOf("/head") + 6);
        html.delete(head.get(0), head.get(1));
        int index = 0;
        while (html.indexOf("<br>", index) != -1) { //kill <br>
            int actualBr = html.indexOf("<br>");
            html.delete(actualBr, actualBr + 4);
            index = actualBr;
        }
        index = 0;
        while (html.indexOf("", index) != -1) { //kill <br>
            int actual = html.indexOf("");
            html.replace(actual, actual + 2, "");
            index = actual + 10;
            //System.out.println("Another  deleted: " + html.substring(actual - 5, actual +20));
        }
        index = 0;
        while (html.indexOf("", index) != -1) { //kill <br>
            int actual = html.indexOf("");
            html.replace(actual, actual + 2, "");
            index = actual + 10;
            //System.out.println("Another  deleted: " + html.substring(actual - 5, actual +20));
        }
        index = 0;
        while (html.indexOf("", index) != -1) { //kill <br>
            int actual = html.indexOf("");
            html.replace(actual, actual + 2, "");
            index = actual + 10;
            //System.out.println("Another  deleted: " + html.substring(actual - 5, actual +20));
        }
        JSONObject myJSON = XML.toJSONObject(html.toString());
        JSONArray coursesL1 = myJSON.getJSONObject("html").getJSONObject("body").getJSONArray("div")
                .getJSONObject(1).getJSONObject("table").getJSONObject("tbody").getJSONArray("tr");
        JSONObject itemsO = coursesL1.getJSONObject(4).getJSONArray("td").getJSONObject(0);
        //System.out.println(itemsO.keySet());
        for (int i = 2; i < coursesL1.length(); i++) {
            JSONArray tds = coursesL1.getJSONObject(i).getJSONArray("td");
            for (int j = 0; j < tds.length(); j++) {
                JSONObject entry = tds.getJSONObject(j);
                Set<String> contents = entry.keySet();
                if (contents.contains("a")) {
                    Course newCourse = new Course();
                    JSONObject actualCourse = entry.getJSONObject("a");

                    JSONArray courseContent = actualCourse.getJSONArray("content");
                    newCourse.setTitle(courseContent.getString(1));
                    String courseTimes = actualCourse.getJSONObject("span").getJSONArray("div").getString(1);
                    String[] splits = courseTimes.split(" ");
                    String day = splits[1].substring(0, 2);
                    String month = splits[1].substring(3, 5);
                    String year = splits[1].substring(6, 8);

                    String[] times = splits[2].split("-");
                    String[] startTime = times[0].split(":");
                    String[] endTime = times[1].split(":");
                    int i_day = Integer.parseInt(day);
                    int i_month = Integer.parseInt(month);
                    int i_year = Integer.parseInt(year) + 2000;
                    int i_startHours = Integer.parseInt(startTime[0]);
                    int i_startMinutes = Integer.parseInt(startTime[1]);
                    int i_endHours = Integer.parseInt(endTime[0]);
                    int i_endMinutes = Integer.parseInt(endTime[1]);
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm");
                    Date startDate = format.parse(
                            i_year + "-" + i_month + "-" + i_day + " " + i_startHours + "-" + i_startMinutes);
                    Date endDate = format.parse(
                            i_year + "-" + i_month + "-" + i_day + " " + i_endHours + "-" + i_endMinutes);
                    newCourse.setStartDate(startDate);
                    newCourse.setEndDate(endDate);
                    courses.add(newCourse);
                }
            }
        }
        return this.courses;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}