Example usage for org.json JSONArray getString

List of usage examples for org.json JSONArray getString

Introduction

In this page you can find the example usage for org.json JSONArray getString.

Prototype

public String getString(int index) throws JSONException 

Source Link

Document

Get the string associated with an index.

Usage

From source file:com.byhook.cordova.chromelauncher.ChromeLauncher.java

/**
 * Executes the request and returns PluginResult.
 * @param action                 The action to execute.
 * @param args                         JSONArry of arguments for the plugin.
 * @param callbackContext                The callback context used when calling back into JavaScript.
 * @return                                 A PluginResult object with a status and message.
 *///from w  w w  .  jav  a 2  s  .  c om
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    if (action.equals("open")) {
        String url = args.getString(0);

        Intent i = new Intent("android.intent.action.MAIN");
        i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
        i.addCategory("android.intent.category.LAUNCHER");
        i.setData(Uri.parse(url));
        ((Activity) cordova).startActivity(i);
    } else if (action.equals("checkInstall")) {
        if (isInstalled("com.android.chrome")) {
            callbackContext.sendPluginResult(new PluginResult(status, true));
            return true;
        } else {
            status = PluginResult.Status.ERROR;
            callbackContext.sendPluginResult(new PluginResult(status, false));
            return true;
        }
    } else if (action.equals("openStore")) {
        Uri marketUri = Uri.parse("market://details?id=com.android.chrome");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
        ((Activity) cordova).startActivity(marketIntent);
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));
    return true;
}

From source file:dhbw.RaplaCalGenerator.HTMLCleaner.java

public ArrayList<Course> generateCourses(String location) {
    try {//w  w  w  .ja  v a 2  s.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;
}

From source file:org.streetpacman.util.DMUtils.java

public static List<DMGeoPoint> JSONArray2GeoPoints(JSONArray jsonArray) throws JSONException {
    List<DMGeoPoint> ptList = new ArrayList<DMGeoPoint>();
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONArray jsonPoint = jsonArray.getJSONArray(i);
        int x = (int) (new Double(jsonPoint.getString(0)) * 1E6);
        int y = (int) (new Double(jsonPoint.getString(1)) * 1E6);
        ptList.add(new DMGeoPoint(x, y));
    }//from w  w w.j  a v a 2  s . c  o m
    return ptList;
}

From source file:net.geco.model.iojson.PersistentStore.java

public void importHeatSets(JSONStore store, Registry registry, Factory factory) throws JSONException {
    JSONArray heatsets = store.getJSONArray(K.HEATSETS);
    for (int i = 0; i < heatsets.length(); i++) {
        JSONObject h = heatsets.getJSONObject(i);
        HeatSet heatset = factory.createHeatSet();
        heatset.setName(h.getString(K.NAME));
        heatset.setQualifyingRank(h.getInt(K.RANK));
        heatset.setSetType(ResultType.valueOf(h.getString(K.TYPE)));
        JSONArray heatz = h.getJSONArray(K.HEATS);
        String[] heats = new String[heatz.length()];
        for (int j = 0; j < heats.length; j++) {
            heats[j] = heatz.getString(j);
        }/*from   w w  w . j av a 2  s . c o  m*/
        heatset.setHeatNames(heats);
        JSONArray poolz = h.getJSONArray(K.POOLS);
        Pool[] pools = new Pool[poolz.length()];
        for (int j = 0; j < pools.length; j++) {
            pools[j] = store.retrieve(poolz.getInt(j), Pool.class);
        }
        heatset.setSelectedPools(pools);
        registry.addHeatSet(heatset);
    }
}

From source file:net.geco.model.iojson.PersistentStore.java

public void importRunnersData(JSONStore store, Registry registry, Factory factory) throws JSONException {
    final int I_RUNNER = 0;
    final int I_ECARD = 1;
    final int I_RESULT = 2;
    JSONArray runnersData = store.getJSONArray(K.RUNNERS_DATA);
    for (int i = 0; i < runnersData.length(); i++) {
        JSONArray runnerTuple = runnersData.getJSONArray(i);

        JSONObject c = runnerTuple.getJSONObject(I_RUNNER);
        Runner runner = factory.createRunner();
        runner.setStartId(c.getInt(K.START_ID));
        runner.setFirstname(c.getString(K.FIRST));
        runner.setLastname(c.getString(K.LAST));
        runner.setEcard(c.getString(K.ECARD));
        runner.setClub(store.retrieve(c.getInt(K.CLUB), Club.class));
        runner.setCategory(store.retrieve(c.getInt(K.CAT), Category.class));
        runner.setCourse(store.retrieve(c.getInt(K.COURSE), Course.class));
        runner.setRegisteredStarttime(new Date(c.getLong(K.START)));
        runner.setArchiveId((Integer) c.opt(K.ARK));
        runner.setRentedEcard(c.optBoolean(K.RENT));
        runner.setNC(c.optBoolean(K.NC));
        registry.addRunner(runner);/*from  ww w  .  j  a va2s.  c  o  m*/

        JSONObject d = runnerTuple.getJSONObject(I_ECARD);
        RunnerRaceData raceData = factory.createRunnerRaceData();
        raceData.setStarttime(new Date(d.getLong(K.START)));
        raceData.setFinishtime(new Date(d.getLong(K.FINISH)));
        raceData.setControltime(new Date(d.getLong(K.CHECK)));
        raceData.setReadtime(new Date(d.getLong(K.READ)));
        JSONArray p = d.getJSONArray(K.PUNCHES);
        Punch[] punches = new Punch[p.length() / 2];
        for (int j = 0; j < punches.length; j++) {
            punches[j] = factory.createPunch();
            punches[j].setCode(p.getInt(2 * j));
            punches[j].setTime(new Date(p.getLong(2 * j + 1)));
        }
        raceData.setPunches(punches);
        raceData.setRunner(runner);
        registry.addRunnerData(raceData);

        JSONObject r = runnerTuple.getJSONObject(I_RESULT);
        TraceData traceData = factory.createTraceData();
        traceData.setNbMPs(r.getInt(K.MPS));
        traceData.setNbExtraneous(r.optInt(K.EXTRA)); // MIGR v2.x -> v2.3
        JSONArray t = r.getJSONArray(K.TRACE);
        Trace[] trace = new Trace[t.length() / 2];
        for (int j = 0; j < trace.length; j++) {
            trace[j] = factory.createTrace(t.getString(2 * j), new Date(t.getLong(2 * j + 1)));
        }
        if (r.has(K.SECTION_DATA)) {
            SectionTraceData sectionData = (SectionTraceData) traceData;
            JSONArray sections = r.getJSONArray(K.SECTION_DATA);
            for (int j = 0; j < sections.length(); j++) {
                JSONArray section = sections.getJSONArray(j);
                sectionData.putSectionAt(store.retrieve(section.getInt(0), Section.class), section.getInt(1));
            }
        }
        JSONArray neut = r.getJSONArray(K.NEUTRALIZED);
        for (int j = 0; j < neut.length(); j++) {
            trace[neut.getInt(j)].setNeutralized(true);
        }
        traceData.setTrace(trace);
        raceData.setTraceData(traceData);

        RunnerResult result = factory.createRunnerResult();
        result.setRaceTime(r.optLong(K.RACE_TIME, TimeManager.NO_TIME_l)); // MIGR v2.x -> v2.2
        result.setResultTime(r.getLong(K.TIME));
        result.setStatus(Status.valueOf(r.getString(K.STATUS)));
        result.setTimePenalty(r.getLong(K.PENALTY));
        result.setManualTimePenalty(r.optLong(K.MANUAL_PENALTY, 0)); // MIGR v2.x -> v2.3
        raceData.setResult(result);
    }
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for listContacts method with mandatory parameters.
 *//*from  ww  w. j  a v  a 2  s  . c o m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSetContactNegativeCase" }, description = "BaseCRM {listContacts} integration test with mandatory parameters.")
public void testListContactsWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listContacts_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    JSONArray esbContactsArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    JSONObject esbContactObject = new JSONObject(esbContactsArray.getString(0));

    String apiEndPoint = salesApiEndpoint + "contacts.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiContactsArray = new JSONArray(apiRestResponse.getBody().getString("output"));
    JSONObject apiContactObject = new JSONObject(apiContactsArray.getString(0));

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbContactObject.getJSONObject("contact").getString("id"),
            apiContactObject.getJSONObject("contact").getString("id"));
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getContactNotes method with mandatory parameters.
 *///from www  . ja  v  a  2  s  .co m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateContactNoteNegativeCase" }, description = "BaseCRM {getContactNotes} integration test with mandatory parameters.")
public void testGetContactNotesWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getContactNotes_mandatory.json", parametersMap);

    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "contacts/" + connectorProperties.getProperty("contactIdMandatory")
            + "/notes.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    String esbNoteContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note")
            .getString("content");
    String esbNoteId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note").getString("id");

    int esbNotesCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbNotesCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbNoteId.equals(object.getJSONObject("note").getString("id"))
                && esbNoteContent.equals(object.getJSONObject("note").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getContactReminders method with mandatory parameters.
 *///from   w w w  . jav a2  s.co m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateContactReminderNegativeCase" }, description = "BaseCRM {getContactReminders} integration test with mandatory parameters.")
public void testGetContactRemindersWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getContactReminders_mandatory.json", parametersMap);
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "contacts/" + connectorProperties.getProperty("contactIdMandatory")
            + "/reminders.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbRemindersCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    String esbReminderContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder")
            .getString("content");
    String esbReminderId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbRemindersCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbReminderId.equals(object.getJSONObject("reminder").getString("id"))
                && esbReminderContent.equals(object.getJSONObject("reminder").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getDealNotes method with mandatory parameters.
 *//*from   w  w  w .jav a 2 s  . c o  m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateDealNoteNegativeCase" }, description = "BaseCRM {getDealNotes} integration test with mandatory parameters.")
public void testGetDealNotesWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getDealNotes_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "deals/" + connectorProperties.getProperty("dealIdMandatory")
            + "/notes.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbNotesCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    String esbNoteContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note")
            .getString("content");
    String esbNoteId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbNotesCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbNoteId.equals(object.getJSONObject("note").getString("id"))
                && esbNoteContent.equals(object.getJSONObject("note").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getDealReminders method with mandatory parameters.
 *///  w  ww.java 2  s. co  m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateDealReminderNegativeCase" }, description = "BaseCRM {getDealReminders} integration test with mandatory parameters.")
public void testGetDealRemindersWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getDealReminders_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "deals/" + connectorProperties.getProperty("dealIdMandatory")
            + "/reminders.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbRemindersCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    String esbReminderContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder")
            .getString("content");
    String esbReminderId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbRemindersCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbReminderId.equals(object.getJSONObject("reminder").getString("id"))
                && esbReminderContent.equals(object.getJSONObject("reminder").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}