Example usage for org.json JSONArray JSONArray

List of usage examples for org.json JSONArray JSONArray

Introduction

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

Prototype

public JSONArray(Object array) throws JSONException 

Source Link

Document

Construct a JSONArray from an array

Usage

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for getNotifications method with optional parameters.
 *///from  w  w  w. j a va2 s.  c  o  m
@Test(priority = 1, dependsOnMethods = {
        "testGetNotificationsWithMandatoryParameters" }, description = "github {getNotifications} integration test with optional parameters.")
public void testGetNotificationsWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getNotifications_optional.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/notifications?all=true";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for getRepositoryNotifications method with mandatory parameters.
 *//*  www .jav  a  2 s  . c  o m*/
@Test(priority = 1, dependsOnMethods = {
        "testGetNotificationsWithNegativeCase" }, description = "github {getRepositoryNotifications} integration test with mandatory parameters.")
public void testGetRepositoryNotificationsWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getRepositoryNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getRepositoryNotifications_mandatory.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/notifications";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for getRepositoryNotifications method with optional parameters.
 *///from  w  ww .j a  v a2s  . c  o m
@Test(priority = 1, dependsOnMethods = {
        "testGetRepositoryNotificationsWithMandatoryParameters" }, description = "github {getRepositoryNotifications} integration test with optional parameters.")
public void testGetRepositoryNotificationsWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getRepositoryNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getRepositoryNotifications_optional.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/notifications?all=true";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:com.amazon.android.model.content.Content.java

/**
 * Set content tags. Warning: This method expects the tags value to be in a list format that
 * can be turned into a {@link JSONArray}. If its not errors may occur.
 *
 * @param tags Content tags as a string representation of a JSON array.
 * @throws ListUtils.ExpectingJsonArrayException Thrown if tags is not a JSON array string.
 *//* w ww. ja  va  2s . c  om*/
public void setTags(String tags) throws ListUtils.ExpectingJsonArrayException {

    if (tags == null) {
        mTags = "[]";
        return;
    }
    // Make sure tags is a real JSON array string.
    try {
        new JSONArray(mTags);
    } catch (JSONException e) {
        throw new ListUtils.ExpectingJsonArrayException(mTags);
    }
    mTags = tags;
}

From source file:com.amazon.android.model.content.Content.java

/**
 * Set the list of recommendations to recommend.
 *
 * @param recommendations List of content ids as a string representation of a JSON array.
 * @throws ListUtils.ExpectingJsonArrayException Thrown if the recommendations string is not a
 *                                               JSON array string.
 *//*  w ww .jav  a2  s  . com*/
public void setRecommendations(String recommendations) throws ListUtils.ExpectingJsonArrayException {

    if (recommendations == null) {
        mRecommendations = "[]";
        return;
    }
    // Make sure recommendations is a real JSON array string.
    try {
        new JSONArray(mRecommendations);
    } catch (JSONException e) {
        throw new ListUtils.ExpectingJsonArrayException(mRecommendations);
    }
    mRecommendations = recommendations;
}

From source file:nl.hnogames.domoticzapi.Parsers.SwitchesParser.java

@Override
public void parseResult(String result) {
    try {//from w  w  w.ja  va 2s . c o m
        JSONArray jsonArray = new JSONArray(result);
        ArrayList<SwitchInfo> mSwitches = new ArrayList<>();

        if (jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject row = jsonArray.getJSONObject(i);
                mSwitches.add(new SwitchInfo(row));
            }
        }

        switchesReceiver.onReceiveSwitches(mSwitches);
    } catch (JSONException e) {
        Log.e(TAG, "ScenesParser JSON exception");
        e.printStackTrace();
        switchesReceiver.onError(e);
    }
}

From source file:koubachi.internal.json.JSONFactory.java

public ArrayList<Device> createDeviceList(String jsonData) {
    try {/*  w  w  w  . jav a 2s.c o  m*/
        JSONArray jsonArray = new JSONArray(jsonData);
        return createDeviceList(jsonArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:koubachi.internal.json.JSONFactory.java

public ArrayList<Plant> createPlantList(String jsonData) {
    try {//from www . j a v  a 2  s  . co m
        JSONArray jsonArray = new JSONArray(jsonData);
        return createPlantList(jsonArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;

}

From source file:koubachi.internal.json.JSONFactory.java

public ArrayList<PlantCareAdvice> createPlantCareList(String jsonData) {
    try {//from  w w  w.ja  v a2  s  .c om
        JSONArray jsonArray = new JSONArray(jsonData);
        return createPlantCareList(jsonArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.billthefarmer.tuner.MainActivity.java

void getPreferences() {
    // Load preferences

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Set preferences
    if (audio != null) {
        audio.input = Integer.parseInt(preferences.getString(PREF_INPUT, "0"));
        audio.reference = preferences.getInt(PREF_REFERENCE, 440);
        audio.transpose = Integer.parseInt(preferences.getString(PREF_TRANSPOSE, "0"));

        audio.filter = preferences.getBoolean(PREF_FILTER, false);
        audio.downsample = preferences.getBoolean(PREF_DOWNSAMPLE, false);
        audio.multiple = preferences.getBoolean(PREF_MULTIPLE, false);
        audio.screen = preferences.getBoolean(PREF_SCREEN, false);
        audio.strobe = preferences.getBoolean(PREF_STROBE, false);
        audio.zoom = preferences.getBoolean(PREF_ZOOM, true);

        // Check screen
        if (audio.screen) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }// w w w  .  ja  v a  2 s  . co  m

        else {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }

        // Check for strobe before setting colours
        if (strobe != null) {
            strobe.colour = Integer.valueOf(preferences.getString(PREF_COLOUR, "0"));

            if (strobe.colour == 3) {
                JSONArray custom;

                try {
                    custom = new JSONArray(preferences.getString(PREF_CUSTOM, null));

                    strobe.foreground = custom.getInt(0);
                    strobe.background = custom.getInt(1);
                }

                catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            // Ensure the view dimensions have been set
            if (strobe.width > 0 && strobe.height > 0)
                strobe.createShaders();
        }
    }
}