Example usage for org.json JSONObject getString

List of usage examples for org.json JSONObject getString

Introduction

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

Prototype

public String getString(String key) throws JSONException 

Source Link

Document

Get the string associated with a key.

Usage

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for createWebPropertyUserLinks method with mandatory parameters.
 *
 * @throws org.json.JSONException/*from w  ww  .  j  a va2 s  . c  om*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {createWebPropertyUserLinks} integration test with mandatory parameters.")
public void testCreateWebPropertyUserLinksWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createWebPropertyUserLinks");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createWebPropertyUserLinks_mandatory.json");
    final JSONObject esbResponse = esbRestResponse.getBody();
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbResponse.getString("kind"), "analytics#entityUserLink");
    String userLinkId = esbResponse.getString("id");
    connectorProperties.put("userLinkId", userLinkId);

}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for updateWebPropertyUserLinks method with mandatory parameters.
 *
 * @throws org.json.JSONException//from  w  w  w . ja  v  a  2 s . c om
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {updateWebPropertyUserLinks} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateWebPropertyUserLinksWithMandatoryParameters" })
public void testUpdateWebPropertyUserLinksWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:updateWebPropertyUserLinks");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_updateWebPropertyUserLinks_mandatory.json");
    final JSONObject esbResponse = esbRestResponse.getBody();
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbResponse.getString("kind"), "analytics#entityUserLink");
    String userLinkId = esbResponse.getString("id");
    connectorProperties.put("userLinkId", userLinkId);

}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for updateWebProperties method with mandatory parameters.
 *
 * @throws org.json.JSONException//from   ww  w  . j  a v  a 2s  . com
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {updateWebProperties} integration test with mandatory parameters.")
public void testUpdateWebPropertiesWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:updateWebProperties");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_updateWebProperties_mandatory.json");
    final JSONObject esbResponse = esbRestResponse.getBody();
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbResponse.getString("kind"), "analytics#webproperty");
    String userLinkId = esbResponse.getString("id");
    connectorProperties.put("userLinkId", userLinkId);

}

From source file:de.devmil.common.licensing.PackageInfo.java

public static PackageInfo readFromJSON(JSONObject obj, ILicenseAccess licenseAccess) {
    try {// w w w  .j  av  a2  s  .c o  m
        String name = obj.getString(NAME_IDENTIFIER);
        String vendor = obj.getString(VENDOR_IDENTIFIER);
        String licenseId = obj.getString(LICENSE_IDENTIFIER);
        String url = obj.getString(URL_IDENTIFIER);
        String copyright = obj.getString(COPYRIGHT_IDENTIFIER);
        String iconName = obj.getString(ICON_IDENTIFIER);
        PackageInfo result = new PackageInfo(name, vendor, licenseId, url, copyright, iconName, licenseAccess);

        return result;
    } catch (JSONException e) {
        LOGW(PackageInfo.class.getSimpleName(), "Error reading LicenseDefinition", e);
        return null;
    }
}

From source file:com.streaming.sweetplayer.fragment.TopFragment.java

private void getTopList() {
    JSONParser jsonParser = new JSONParser();
    JSONArray jsonArray;//from w ww  .j a  v  a  2  s  .  c om

    try {
        JSONObject json = jsonParser.getJSONFromUrl(Config.TOP_URL);
        if (json != null) {
            jsonArray = json.getJSONArray(Config.SONGS_ITEM);
            int array_length = jsonArray.length();
            if (array_length > 0) {
                for (int i = 0; i < array_length; i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    map.put(Config.ID, jsonObject.getString(Config.ID));
                    map.put(Config.ARTIST, jsonObject.getString(Config.ARTIST));
                    map.put(Config.NAME, jsonObject.getString(Config.SONG));
                    map.put(Config.MP3, jsonObject.getString(Config.MP3));
                    map.put(Config.DURATION, jsonObject.getString(Config.DURATION));
                    map.put(Config.URL, jsonObject.getString(Config.URL));
                    map.put(Config.IMAGE, jsonObject.getString(Config.IMAGE));
                    mTopList.add(map);
                }
            } else {
                // Showing a message should be done in the UI thread.
                mActivity.runOnUiThread(new Runnable() {
                    public void run() {
                        Utils.showUserMessage(mActivity.getApplicationContext(),
                                mActivity.getString(R.string.search_empty));
                    }
                });
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:io.crate.frameworks.mesos.api.CrateRestResource.java

@Nullable
String mesosMasterAddress() {/*from   www . ja va2  s.  co  m*/
    try (CuratorFramework cf = zkClient()) {
        cf.start();
        List<String> children = cf.getChildren().forPath("/mesos");
        List<Integer> masterIds = new ArrayList<Integer>();
        if (children.isEmpty()) {
            return null;
        }
        JSONObject cfData = null;

        for (String child : children) {
            if (child.startsWith("json.info")) {
                masterIds.add(Integer.parseInt(child.split("_")[1]));
            }
        }
        Collections.sort(masterIds);
        for (String child : children) {
            if (child.endsWith(String.valueOf(masterIds.get(0)))) {
                cfData = new JSONObject(new String(cf.getData().forPath("/mesos/" + child)));
                break;
            }
        }

        if (cfData != null) {
            JSONObject address = cfData.getJSONObject("address");
            return String.format("%s:%d", address.getString("ip"), address.getInt("port"));
        }
    } catch (Exception e) {
        LOGGER.error("Error while obtaining a mesos address from the curator framework: ", e);
    }
    return null;
}

From source file:com.hyphenated.pokerplayerclient.domain.PlayerStatus.java

public PlayerStatus(JSONObject json) {
    try {//w ww  .  j  ava 2s  .  c o m
        status = PlayerStatusType.valueOf(json.getString("status"));
        if (json.has("card1")) {
            this.card1 = Card.getCardByIdentifier(json.getString("card1"));
            this.card2 = Card.getCardByIdentifier(json.getString("card2"));
        }
        if (json.has("chips")) {
            this.chips = json.getInt("chips");
        }
        if (json.has("amountBetRound")) {
            this.amountBetRound = json.getInt("amountBetRound");
        }
        if (json.has("amountToCall")) {
            this.amountToCall = json.getInt("amountToCall");
        }
        if (json.has("smallBlind")) {
            this.smallBlind = json.getInt("smallBlind");
        }
        if (json.has("bigBlind")) {
            this.bigBlind = json.getInt("bigBlind");
        }
    } catch (JSONException e) {
        Log.e("Poker", e.getMessage());
    }
}

From source file:io.teak.sdk.RemoteConfiguration.java

public static void requestConfigurationForApp(final Session session) {
    HashMap<String, Object> payload = new HashMap<>();
    payload.put("id", session.appConfiguration.appId);

    new Thread(new Request("gocarrot.com", "/games/" + session.appConfiguration.appId + "/settings.json",
            payload, session) {//from  w  w  w  . j  av  a  2s  . c  om
        @Override
        protected void done(int responseCode, String responseBody) {
            try {
                JSONObject response = new JSONObject(responseBody);

                RemoteConfiguration configuration = new RemoteConfiguration(session.appConfiguration,
                        response.isNull("auth") ? "gocarrot.com" : response.getString("auth"),
                        nullInsteadOfEmpty(response.isNull("sdk_sentry_dsn") ? null
                                : response.getString("sdk_sentry_dsn")),
                        nullInsteadOfEmpty(response.isNull("app_sentry_dsn") ? null
                                : response.getString("app_sentry_dsn")));

                synchronized (eventListenersMutex) {
                    for (EventListener e : RemoteConfiguration.eventListeners) {
                        e.onConfigurationReady(configuration);
                    }
                }
            } catch (Exception e) {
                Log.e(LOG_TAG, "Error processing settings.json " + Log.getStackTraceString(e));
            }
        }
    }).start();
}

From source file:com.imaginary.home.cloud.device.Device.java

static void mapDevice(@Nonnull ControllerRelay relay, @Nonnull JSONObject json,
        @Nonnull Map<String, Object> state) throws JSONException {
    state.put("relayId", relay.getControllerRelayId());
    state.put("deviceId", UUID.randomUUID().toString());
    if (json.has("name") && !json.isNull("name")) {
        state.put("name", json.getString("name"));
    }//from   w w  w.  j  ava 2 s .co  m
    if (json.has("description") && !json.isNull("description")) {
        state.put("description", json.getString("description"));
    }
    if (json.has("model") && !json.isNull("model")) {
        state.put("model", json.getString("model"));
    }
    if (json.has("deviceId") && !json.isNull("deviceId")) {
        state.put("vendorDeviceId", json.getString("deviceId"));
    }
    if (json.has("systemId") && !json.isNull("systemId")) {
        state.put("homeAutomationSystemId", json.getString("systemId"));
    }
}

From source file:org.indigo.cdmi.backend.radosgw.JsonResponseTranlator.java

/**
 * Retrieves object type from passed JSON object. 
 * The assumption is that profileInfo represents QoS profile in JSON format. 
 * /*from   w  w w.j  av a  2s . c o m*/
 * @param profileInfo QoS profile description as JSON object (in JSONObject format).
 * @return String which represents object type of derived from profileInfo 
 *     (object type is container or dataobject).
 */
private String retriveObjectTypeAsString(JSONObject profileInfo) {

    String typeAsString = profileInfo.getString(JSON_KEY_TYPE);
    return typeAsString;

}