Example usage for org.json JSONObject getBoolean

List of usage examples for org.json JSONObject getBoolean

Introduction

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

Prototype

public boolean getBoolean(String key) throws JSONException 

Source Link

Document

Get the boolean value associated with a key.

Usage

From source file:cn.ttyhuo.activity.InfoOwnerActivity.java

protected void setupViewOfHasLogin(JSONObject jObject) {
    try {//from  w w w . ja  v  a 2 s.c o  m

        ArrayList<String> pics = new ArrayList<String>();
        JSONArray jsonArray = jObject.optJSONArray("imageList");
        if (jsonArray != null) {
            for (int s = 0; s < jsonArray.length(); s++)
                pics.add(jsonArray.getString(s));
        }
        while (pics.size() < 3)
            pics.add("plus");
        mPicData = pics;
        mPicAdapter.updateData(pics);

        if (jObject.getBoolean("isTruckVerified")) {
            tv_edit_tips.setText("?????");
        } else if (jsonArray != null && jsonArray.length() > 2 && jObject.has("truckInfo")) {
            tv_edit_tips.setText(
                    "?????????");
        } else {
            tv_edit_tips.setText("??????");
        }

        if (jObject.has("truckInfo")) {
            JSONObject userJsonObj = jObject.getJSONObject("truckInfo");
            if (!userJsonObj.optString("licensePlate").isEmpty()
                    && userJsonObj.optString("licensePlate") != "null")
                mEditChepai.setText(userJsonObj.getString("licensePlate"));
            Integer truckType = userJsonObj.getInt("truckType");
            if (truckType != null && truckType > 0)
                mEditChexing.setText(ConstHolder.TruckTypeItems[truckType - 1]);
            else
                mEditChexing.setText("");
            if (!userJsonObj.optString("loadLimit").isEmpty() && userJsonObj.optString("loadLimit") != "null")
                mEditZaizhong.setText(userJsonObj.getString("loadLimit"));
            if (!userJsonObj.optString("truckLength").isEmpty()
                    && userJsonObj.optString("truckLength") != "null")
                mEditChechang.setText(userJsonObj.getString("truckLength"));
            if (!userJsonObj.optString("modelNumber").isEmpty()
                    && userJsonObj.optString("modelNumber") != "null")
                mEditXinghao.setText(userJsonObj.getString("modelNumber"));

            if (!userJsonObj.optString("seatingCapacity").isEmpty()
                    && userJsonObj.optString("seatingCapacity") != "null")
                mEditZuowei.setText(userJsonObj.getString("seatingCapacity"));
            if (!userJsonObj.optString("releaseYear").isEmpty()
                    && userJsonObj.optString("releaseYear") != "null")
                mEditDate.setText(userJsonObj.getString("releaseYear") + "");
            if (!userJsonObj.optString("truckWidth").isEmpty() && userJsonObj.optString("truckWidth") != "null")
                mEditKuan.setText(userJsonObj.getString("truckWidth"));
            if (!userJsonObj.optString("truckHeight").isEmpty()
                    && userJsonObj.optString("truckHeight") != "null")
                mEditGao.setText(userJsonObj.getString("truckHeight"));
        }

        if (!jObject.getBoolean("isTruckVerified")) {
            mEditChexing.setOnClickListener(this);
            mEditDate.setOnClickListener(this);
            mEditChepai.setFocusable(true);
            mEditChepai.setEnabled(true);
            mEditZaizhong.setFocusable(true);
            mEditZaizhong.setEnabled(true);
            mEditChechang.setFocusable(true);
            mEditChechang.setEnabled(true);
            mEditZuowei.setFocusable(true);
            mEditZuowei.setEnabled(true);
            mEditKuan.setFocusable(true);
            mEditKuan.setEnabled(true);
            mEditGao.setFocusable(true);
            mEditGao.setEnabled(true);
            mEditXinghao.setFocusable(true);
            mEditXinghao.setEnabled(true);
            canUpdate = true;
        } else {
            mPicGrid.setOnItemLongClickListener(null);

            mEditChepai.setFocusable(false);
            mEditChepai.setEnabled(false);
            mEditZaizhong.setFocusable(false);
            mEditZaizhong.setEnabled(false);
            mEditChechang.setFocusable(false);
            mEditChechang.setEnabled(false);
            mEditZuowei.setFocusable(false);
            mEditZuowei.setEnabled(false);
            mEditKuan.setFocusable(false);
            mEditKuan.setEnabled(false);
            mEditGao.setFocusable(false);
            mEditGao.setEnabled(false);
            mEditXinghao.setFocusable(false);
            mEditXinghao.setEnabled(false);
            canUpdate = false;
        }

        saveParams(true);

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

From source file:net.zorgblub.typhon.dto.PageOffsets.java

public static PageOffsets fromJSON(String json) throws JSONException {
    JSONObject offsetsObject = new JSONObject(json);
    PageOffsets result = new PageOffsets();

    result.fontFamily = offsetsObject.getString(Fields.fontFamily.name());
    result.fontSize = offsetsObject.getInt(Fields.fontSize.name());
    result.vMargin = offsetsObject.getInt(Fields.vMargin.name());
    result.hMargin = offsetsObject.getInt(Fields.hMargin.name());
    result.lineSpacing = offsetsObject.getInt(Fields.lineSpacing.name());
    result.fullScreen = offsetsObject.getBoolean(Fields.fullScreen.name());
    result.algorithmVersion = offsetsObject.optInt(Fields.algorithmVersion.name(), -1);
    result.allowStyling = offsetsObject.optBoolean(Fields.allowStyling.name(), true);

    result.offsets = readOffsets(offsetsObject.getJSONArray(Fields.offsets.name()));

    return result;
}

From source file:com.github.koraktor.steamcondenser.community.AppNews.java

/**
 * Creates a new instance of an AppNews news item with the given data
 *
 * @param appId The unique Steam Application ID of the game (e.g.
 *        <code>440</code> for Team Fortress 2). See
 *        http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
 *        all application IDs/* w  ww  .j av  a 2  s .  co  m*/
 * @param newsData The news data extracted from JSON
 * @throws WebApiException if the JSON data cannot be parsed
 */
private AppNews(int appId, JSONObject newsData) throws WebApiException {
    try {
        this.appId = appId;
        this.author = newsData.getString("author");
        this.contents = newsData.getString("contents").trim();
        this.date = new Date(newsData.getLong("date"));
        this.external = newsData.getBoolean("is_external_url");
        this.feedLabel = newsData.getString("feedlabel");
        this.feedName = newsData.getString("feedname");
        this.gid = newsData.getLong("gid");
        this.title = newsData.getString("title");
        this.url = newsData.getString("url");
    } catch (JSONException e) {
        throw new WebApiException("Could not parse JSON data.", e);
    }
}

From source file:de.dmxcontrol.executor.EntityExecutor.java

public static EntityExecutor Receive(JSONObject o) {
    EntityExecutor entity = null;/*from  w  w  w . ja  v  a  2  s  . c  om*/
    try {
        if (o.getString("Type").equals(NetworkID)) {
            entity = new EntityExecutor(o.getInt("Number"), o.getString("Name"));
            entity.guid = o.getString("GUID");
            if (o.has("Value")) {
                entity.value = Float.parseFloat(o.getString("Value").replace(",", "."));
            }
            if (o.has("Flash")) {
                entity.flash = o.getBoolean("Flash");
            }
            if (o.has("Toggle")) {
                entity.toggle = o.getBoolean("Toggle");
            }
            if (o.has("FaderMode")) {
                entity.faderMode = o.getInt("FaderMode");
            }
        }
    } catch (Exception e) {
        Log.e("UDP Listener", e.getMessage());
        DMXControlApplication.SaveLog();
    }
    o = null;
    if (o == null) {
        ;
    }
    return entity;
}

From source file:com.example.android.samplesync.client.RawContact.java

/**
 * Creates and returns an instance of the RawContact from the provided JSON data.
 *
 * @param user The JSONObject containing user data
 * @return user The new instance of Sample RawContact created from the JSON data.
 *//* w  w  w  .  j  a  v  a  2  s.c  o m*/
public static RawContact valueOf(JSONObject contact) {

    try {
        final String userName = !contact.isNull("u") ? contact.getString("u") : null;
        final int serverContactId = !contact.isNull("i") ? contact.getInt("i") : -1;
        // If we didn't get either a username or serverId for the contact, then
        // we can't do anything with it locally...
        if ((userName == null) && (serverContactId <= 0)) {
            throw new JSONException("JSON contact missing required 'u' or 'i' fields");
        }

        final int rawContactId = !contact.isNull("c") ? contact.getInt("c") : -1;
        final String firstName = !contact.isNull("f") ? contact.getString("f") : null;
        final String lastName = !contact.isNull("l") ? contact.getString("l") : null;
        final String cellPhone = !contact.isNull("m") ? contact.getString("m") : null;
        final String officePhone = !contact.isNull("o") ? contact.getString("o") : null;
        final String homePhone = !contact.isNull("h") ? contact.getString("h") : null;
        final String email = !contact.isNull("e") ? contact.getString("e") : null;
        final String status = !contact.isNull("s") ? contact.getString("s") : null;
        final String avatarUrl = !contact.isNull("a") ? contact.getString("a") : null;
        final boolean deleted = !contact.isNull("d") ? contact.getBoolean("d") : false;
        final long syncState = !contact.isNull("x") ? contact.getLong("x") : 0;
        return new RawContact(userName, null, firstName, lastName, cellPhone, officePhone, homePhone, email,
                status, avatarUrl, deleted, serverContactId, rawContactId, syncState, false);
    } catch (final Exception ex) {
        Log.i(TAG, "Error parsing JSON contact object" + ex.toString());
    }
    return null;
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {/*from   ww w  .jav  a2 s . c  o m*/
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

            // notes
            if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
                setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
            }

            // deleted
            if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
                setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
            }

            // completed
            if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
                setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get task content from jsonobject");
        }
    }
}

From source file:com.zaizi.alfresco.crowd.authentication.filter.CrowdSSOFilter.java

/**
 * <p>/*from w  ww  . ja v  a 2 s .c o m*/
 * The filter checks if a crowd cookie exists in the request in order to try to authenticate automatically
 * the user
 * </p>
 * 
 * @param request
 *            The request
 * @param response
 *            The response
 * @param chain
 *            The filter chain containing the rest of the configured filters
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String endpoint = this.frameworkUtils.getEndpoint(ENDPOINT_ID).getEndpointUrl();

    /* Create a Remote client for the configured endpoint id */
    RemoteClient remote = createRemoteClient(endpoint, httpRequest.getSession(true));

    /* Manages the cookies */
    CookieManager cookieManager = new CookieManager();

    String cookieValue = null;
    Boolean crowdCookiePresent = false;

    try {
        cookieValue = cookieManager.getCookieValue(httpRequest, CROWD_COOKIE_NAME).toString();
        crowdCookiePresent = true;
    } catch (CookieNotFoundException e) {
        logger.debug("Crowd cookie not found in the request");
    }

    /* If authenticated, trying to enable SSO if it is not enabled yet */
    if (AuthenticationUtil.isAuthenticated(httpRequest)) {
        // Checks if Crowd Cookie exists. If not, trying to create a Crowd token to enable SSO
        if (!crowdCookiePresent) {
            enableSSO(remote, cookieManager, httpRequest, httpResponse);
        }

        /* Continue the filter chain */
        chain.doFilter(httpRequest, response);
        return;
    }

    /* If not authenticated and no cookie present, continue the chain */
    if (!crowdCookiePresent) {
        chain.doFilter(httpRequest, httpResponse);
        return;
    }

    /* Cookie present. Trying to create Share session */
    try {

        /* Call the validation token endpoint */
        Response resp = remote.call(String.format(CROWD_TOKEN_VALIDATION_URL, cookieValue));

        /* JSON Response */
        JSONObject jsonResp = new JSONObject(resp.getResponse());

        /* If it is a valid response... */
        if (jsonResp.getBoolean(VALID_KEY)) {
            // Use the token and user to create the session in the connector and share
            String alfTicket = jsonResp.getString(ALF_TICKET_KEY);
            String userId = jsonResp.getString(USER_KEY);

            /* Set credentials in the connector and login the user in Share */
            setUserCredentialsInConnector(httpRequest.getSession(), alfTicket, userId);
            AuthenticationUtil.login(httpRequest, httpResponse, userId);
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    chain.doFilter(httpRequest, httpResponse);

}

From source file:produvia.com.scanner.DevicesActivity.java

/*********************************************************************
 * The WeaverSdk callback indicating that a task has been completed:
 *********************************************************************/
@Override/*from  w w  w. j  a va2  s.  co m*/
public void onTaskCompleted(final int flag, final JSONObject response) {
    if (response == null || mActivityPaused)
        return;
    try {

        if (response.has("responseCode") && response.getInt("responseCode") == 401) {
            //unauthorized:
            runWelcomeActivity();
        }

        switch (flag) {
        case WeaverSdk.ACTION_USER_LOGOUT:
            runWelcomeActivity();
            break;

        case WeaverSdk.ACTION_SERVICES_GET:
            if (response.getBoolean("success")) {
                handleReceivedServices(response.getJSONObject("data"));
            }
            break;

        }

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

From source file:produvia.com.scanner.DevicesActivity.java

/*********************************************************************
 * The WeaverSdk callback indicating that a task update occurred.
 * for example, a new service was discovered in the current network:
 *********************************************************************/
@Override//w  w  w .  j a va  2s  .  c  om
public void onTaskUpdate(int flag, JSONObject response) {
    if (response == null || mActivityPaused)
        return;
    try {
        //this flag indicates that a new service was discovered in the scan:
        if (flag == WeaverSdk.ACTION_SERVICES_SCAN) {
            if (response.getBoolean("success")) {
                handleReceivedServices(response.getJSONObject("data"));
            }
        }
        //when tha scan is running - it'll provide general state information from time to time:
        else if (flag == WeaverSdk.ACTION_SCAN_STATUS) {
            if (response.getBoolean("success")) {
                if (response.getString("info").equals("Scan running")) {
                    mLastScanStartedAt = Calendar.getInstance();
                    showScanProgress(true);
                } else {
                    mScanCycleCounter += 1;
                    showScanProgress(false);
                    //if we haven't found any light services - we'll show an error message:
                    //if we finished the scan - check if we found any devices:
                    if (mScanCycleCounter > 0 && (mDevices == null || mDevices.size() <= 0)) {
                        setErrorMessage(
                                "Weaver didn't detect any services in the network\nPlease make sure you're connected to the wifi\nand restart the app");
                        //stop the scan:
                        WeaverSdkApi.discoveryService(null, false);
                        return;
                    }
                    //stop the discovery service after max scan cycles:
                    if (mScanCycleCounter >= MAX_SCAN_CYCLES)
                        WeaverSdkApi.discoveryService(null, false);

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

}

From source file:produvia.com.scanner.DevicesActivity.java

private void updateServiceDeviceDatabase(JSONObject data) {
    try {//from w  ww .  j a va  2s .  com
        //first add the services to the devices:
        JSONArray services = data.getJSONArray("services");
        for (int i = 0; i < services.length(); i++) {
            JSONObject service = services.getJSONObject(i);
            String device_id = service.getString("device_id");
            JSONObject device = data.getJSONObject("devices_info").getJSONObject(device_id);
            if (!device.has("services"))
                device.put("services", new JSONObject());
            device.getJSONObject("services").put(service.getString("id"), service);
        }

        JSONObject devices = data.getJSONObject("devices_info");
        //loop over the devices and merge them into the device display:
        for (Iterator<String> iter = devices.keys(); iter.hasNext();) {
            String device_id = iter.next();
            JSONObject device = devices.getJSONObject(device_id);
            //if a device card is already present - just merge the data:
            boolean found = false;
            int network_card_idx = -1;
            for (int i = 0; i < mDevices.size(); i++) {
                CustomListItem cli = mDevices.get(i);
                if (cli instanceof DeviceCard && ((DeviceCard) cli).getId().equals(device_id)) {
                    ((DeviceCard) cli).updateInfo(device);
                    found = true;
                    break;
                } else if (cli.getDescription().equals(device.getString("network_id"))) {
                    network_card_idx = i;
                }
            }

            if (!found) {
                if (network_card_idx < 0) {
                    JSONObject network = data.getJSONObject("networks_info")
                            .getJSONObject(device.getString("network_id"));
                    String name = "";
                    if (network.has("name") && network.getString("name") != null)
                        name = network.getString("name");
                    network_card_idx = addNetworkCard(name, device.getString("network_id"),
                            network.getBoolean("user_inside_network"));
                }
                network_card_idx += 1;
                //find the correct index for the card sorted by last seen:
                for (; network_card_idx < mDevices.size(); network_card_idx++) {
                    CustomListItem cli = mDevices.get(network_card_idx);
                    if (!(cli instanceof DeviceCard))
                        break;
                    if (((DeviceCard) cli).getLastSeen()
                            .compareTo(DeviceCard.getLastSeenFromString(device.getString("last_seen"))) < 0)
                        break;
                }

                DeviceCard dc = new DeviceCard(device);
                mDevices.add(network_card_idx, dc);
            }
        }
        notifyDataSetChanged();

    } catch (JSONException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
}