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:org.boris.xlloop.http.JSONCodec.java

private static XLoper decode(JSONObject jo) throws JSONException {
    switch (jo.getInt("type")) {
    case XLoper.xlTypeBool:
        return jo.getBoolean("bool") ? XLBool.TRUE : XLBool.FALSE;
    case XLoper.xlTypeErr:
        return new XLError(jo.getInt("error"));
    case XLoper.xlTypeInt:
        return new XLInt(jo.getInt("int"));
    case XLoper.xlTypeMissing:
        return XLMissing.MISSING;
    case XLoper.xlTypeMulti:
        int rows = jo.getInt("rows");
        int cols = jo.getInt("cols");
        int len = rows * cols;
        XLoper[] a = new XLoper[len];
        JSONArray ja = jo.getJSONArray("array");
        for (int i = 0; i < len; i++) {
            a[i] = decode(ja.getJSONObject(i));
        }//from   www  .j ava  2s  .com
        return new XLArray(a, rows, cols);
    case XLoper.xlTypeNil:
        return XLNil.NIL;
    case XLoper.xlTypeNum:
        return new XLNum(jo.getDouble("num"));
    case XLoper.xlTypeStr:
        return new XLString(jo.getString("str"));
    case XLoper.xlTypeSRef:
        return new XLSRef(jo.getInt("colFirst"), jo.getInt("colLast"), jo.getInt("rowFirst"),
                jo.getInt("rowLast"));
    }

    return null;
}

From source file:org.stockchart.series.SeriesBase.java

public void fromJSONObject(JSONObject j) throws JSONException {
    fName = j.getString("name");
    fIndexOffset = j.getInt("indexOffset");
    fXAxisSide = Axis.Side.valueOf(j.getString("xAxisSide"));
    fYAxisSide = Axis.Side.valueOf(j.getString("yAxisSide"));
    fIsVisible = j.getBoolean("visible");

    fLastValue = j.has("lastValue") ? j.getDouble("lastValue") : Double.NaN;
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void FillScanexData(int nType, String sJSON) {
    GetDataStoped();/*from w w w.j ava 2  s.  co  m*/
    try {
        String sSubData = removeJsonT(sJSON);
        JSONObject rootobj = new JSONObject(sSubData);
        String sStatus = rootobj.getString("Status");
        if (sStatus.equals("OK")) {
            //6. store data to db and in map
            List<Long> naIDs = new ArrayList<Long>();
            JSONArray oResults = rootobj.getJSONArray("Result");
            for (int i = 0; i < oResults.length(); i++) {
                JSONObject jsonObject = oResults.getJSONObject(i);
                long nID = jsonObject.getLong("ID");
                naIDs.add(nID);

                // Add new items

                if (!mmoSubscriptions.containsKey(nID)) {
                    String sTitle = jsonObject.getString("Title");
                    String sLayerName = jsonObject.getString("LayerName");
                    String sWKT = jsonObject.getString("wkt");
                    boolean bSMSEnable = jsonObject.getBoolean("SMSEnable");

                    ScanexSubscriptionItem Item = new ScanexSubscriptionItem(this, nID, sTitle, sLayerName,
                            sWKT, bSMSEnable);
                    mmoSubscriptions.put(nID, Item);
                    SendScanexItem(Item);

                    mbHasChanges = true;
                }

                mmoSubscriptions.get(nID).UpdateFromRemote(msScanexLoginCookie);

            }

            // Remove deleted items
            for (Long id : mmoSubscriptions.keySet()) {
                if (!naIDs.contains(id)) {
                    mmoSubscriptions.remove(id);
                }
            }
            StoreScanexData();
        } else {
            SendError(rootobj.getString("ErrorInfo"));
        }
    } catch (JSONException e) {
        SendError(e.getLocalizedMessage());
        e.printStackTrace();
    }
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void FillData(int nType, String sJSON) {
    GetDataStoped();/*from  ww  w .  j  a v a 2s.c om*/
    try {
        JSONObject jsonMainObject = new JSONObject(sJSON);
        if (jsonMainObject.getBoolean("error")) {
            String sMsg = jsonMainObject.getString("msg");
            SendError(sMsg);
            return;
        }

        if (jsonMainObject.has("rows") && !jsonMainObject.isNull("rows")) {

            JSONArray jsonArray = jsonMainObject.getJSONArray("rows");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                //Log.i(ParseJSON.class.getName(), jsonObject.getString("text"));
                long nId = jsonObject.getLong("fid");

                long nKey = 10000000000L * nType + nId; //as we have values from separte tables we can get same key - to prevent this add big value multiplied on source type
                if (mmoFires.containsKey(nKey))
                    continue;

                int nIconId = 0;
                if (nType == 1) {//user
                    nIconId = R.drawable.ic_eye;
                } else if (nType == 2) {//nasa
                    nIconId = R.drawable.ic_nasa;
                }

                String sDate = jsonObject.getString("date");
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date dtFire = dateFormat.parse(sDate);
                double dfLat = jsonObject.getDouble("lat");
                double dfLon = jsonObject.getDouble("lon");
                double dfDist = jsonObject.getDouble("dist");

                FireItem item = new FireItem(this, nType, nId, dtFire, dfLon, dfLat, dfDist, nIconId);
                mmoFires.put(nKey, item);

                SendItem(item);
                String sMsg = String.format("%s/%.1f %s/%s", item.GetShortCoordinates(), dfDist / 1000,
                        getString(R.string.km), item.GetDateAsString());
                onNotify(nType, sMsg);
            }
        }
    } catch (Exception e) {
        SendError(e.getLocalizedMessage());//         e.printStackTrace();
    }
}

From source file:me.mast3rplan.phantombot.cache.ChannelHostCache.java

private void updateCache() throws Exception {
    Map<String, JSONObject> newCache = Maps.newHashMap();

    JSONObject j;

    if (id == 0) {
        j = TwitchAPIv3.instance().GetChannel(channel);

        if (j.getBoolean("_success")) {
            if (j.getInt("_http") == 200) {
                id = j.getInt("_id");
            }//from  ww  w . j  a v a2 s.  c o m
        }
    }

    if (id == 0) {
        return;
    }

    j = TwitchAPIv3.instance().GetHostUsers(id);

    if (j.getBoolean("_success")) {
        if (j.getInt("_http") == 200) {
            JSONArray hosts = j.getJSONArray("hosts");

            for (int i = 0; i < hosts.length(); i++) {
                newCache.put(hosts.getJSONObject(i).getString("host_login"), hosts.getJSONObject(i));
            }
        } else {
            try {
                throw new Exception("[HTTPErrorException] HTTP " + j.getInt("status") + " "
                        + j.getString("error") + ". req=" + j.getString("_type") + " " + j.getString("_url")
                        + " " + j.getString("_post") + "   "
                        + (j.has("message") && !j.isNull("message") ? "message=" + j.getString("message")
                                : "content=" + j.getString("_content")));
            } catch (Exception e) {
                com.gmt2001.Console.out
                        .println("ChannelHostCache.updateCache>>Failed to update hosts: " + e.getMessage());
                com.gmt2001.Console.err.logStackTrace(e);
            }
        }
    } else {
        try {
            throw new Exception("[" + j.getString("_exception") + "] " + j.getString("_exceptionMessage"));
        } catch (Exception e) {
            if (e.getMessage().startsWith("[SocketTimeoutException]")
                    || e.getMessage().startsWith("[IOException]")) {
                Calendar c = Calendar.getInstance();

                if (lastFail.after(new Date())) {
                    numfail++;
                } else {
                    numfail = 1;
                }

                c.add(Calendar.MINUTE, 1);

                lastFail = c.getTime();

                if (numfail >= 5) {
                    timeoutExpire = c.getTime();
                }
            }

            com.gmt2001.Console.out
                    .println("ChannelHostCache.updateCache>>Failed to update hosts: " + e.getMessage());
            com.gmt2001.Console.err.logStackTrace(e);
        }
    }

    List<String> hosted = Lists.newArrayList();
    List<String> unhosted = Lists.newArrayList();

    for (String key : newCache.keySet()) {
        if (cache == null || !cache.containsKey(key)) {
            hosted.add(key);
        }
    }

    if (cache != null) {
        for (String key : cache.keySet()) {
            if (!newCache.containsKey(key)) {
                unhosted.add(key);
            }
        }
    }

    this.cache = newCache;

    for (String hoster : hosted) {
        EventBus.instance()
                .post(new TwitchHostedEvent(hoster, PhantomBot.instance().getChannel("#" + this.channel)));
    }

    for (String unhoster : unhosted) {
        EventBus.instance()
                .post(new TwitchUnhostedEvent(unhoster, PhantomBot.instance().getChannel("#" + this.channel)));
    }

    if (firstUpdate) {
        firstUpdate = false;
        EventBus.instance()
                .post(new TwitchHostsInitializedEvent(PhantomBot.instance().getChannel("#" + this.channel)));
    }
}

From source file:edu.nimbus.glass.robotvoicecontrol.VoiceControlActivity.java

/**
 * Send the command to the ROS Server on the specialized topic and wait for the reply back.
 * @param command//from w  w  w.  j  a  v  a 2 s  .  c om
 */
private void sendMessage(String command) {

    final String url = HOST_ADDRESS;
    Log.d("SENDING REQUEST", command);
    final WebSocketConnection mConnection = new WebSocketConnection();
    final String to_send = command;

    try {
        Log.d("Socket", "Atempting connection");
        mConnection.connect(url, new WebSocketHandler() {

            boolean message_received = false;

            @Override
            public void onOpen() {
                //send the request
                JSONObject jsonRequest = new JSONObject();

                try {

                    //Create the object and call it correctly using the API for the rosbridge server.
                    jsonRequest.put("op", "call_service");
                    jsonRequest.put("service", "/glass_voice_command");

                    JSONObject args = new JSONObject();
                    args.put("command", to_send);

                    jsonRequest.put("args", args);
                    Log.d("SENDING COMMAND", jsonRequest.toString());

                    mConnection.sendTextMessage(jsonRequest.toString());

                } catch (Exception e) {

                }
                Log.d("Main Connection", "Status: Connected to " + url);

            }

            /** 
             * Display the message we recieved back and close the application.
             */
            @Override
            public void onTextMessage(String payload) {
                Log.d("Main Payload", payload);
                String result_string = "Falure";
                try {
                    JSONObject res = new JSONObject(payload);
                    if (res.getBoolean("result") == false) {
                        result_string = "Service Falure";
                    } else {
                        result_string = res.getJSONObject("values").getString("result");
                    }
                } catch (JSONException e) {
                }
                message_received = true;
                //We got a message back from the server so lets create the cards for selection.
                Card card1 = new Card(getBaseContext());
                card1.setText("Done :\n" + result_string);
                // Don't call this if you're using TimelineManager
                View card1View = card1.toView();
                setContentView(card1View);
                mConnection.disconnect();
                finish();

            }

            /**
             * If it is closed than we have a poor web connection.  Let the user know.
             */
            @Override
            public void onClose(int code, String reason) {
                Log.d("WEBSOCKET CLOSE", code + "");
                //If connection is lost change the view.
                if (code == 3 && !message_received) {
                    Card card1 = new Card(getBaseContext());
                    card1.setText("No Web Connection");
                    View card1View = card1.toView();
                    setContentView(card1View);

                }
            }

        });

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

From source file:fr.bmartel.android.fadecandy.model.FadecandyConfig.java

public FadecandyConfig(JSONObject config) {

    try {//  w w w .  j  a v a  2s. co m

        if (config.has(Constants.CONFIG_LISTEN) && config.has(Constants.CONFIG_VERBOSE)
                && config.has(Constants.CONFIG_COLOR) && config.has(Constants.CONFIG_DEVICES)) {

            JSONArray listen = config.getJSONArray(Constants.CONFIG_LISTEN);

            if (listen.length() > 1) {
                mHost = listen.getString(0);
                mPort = listen.getInt(1);
            }

            mVerbose = config.getBoolean(Constants.CONFIG_VERBOSE);

            mFcColor = new FadecandyColor(config.getJSONObject(Constants.CONFIG_COLOR));

            JSONArray fcDeviceArr = config.getJSONArray(Constants.CONFIG_DEVICES);

            for (int i = 0; i < fcDeviceArr.length(); i++) {
                mFcDevices.add(new FadecandyDevice((JSONObject) fcDeviceArr.get(i)));
            }
        }

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

}

From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenRoute.java

public StationData jsonParseStop(JSONObject json) throws JSONException {
    StationData station = new StationData();

    station.stationId = json.getInt("ID");
    station.stopName = json.getString("Name");
    station.utmCoords[0] = json.getInt("X");
    station.utmCoords[1] = json.getInt("Y");
    station.realtimeStop = json.getBoolean("RealTimeStop");

    return station;
}

From source file:sh.calaba.driver.server.CalabashNodeConfiguration.java

/**
 * Reads the driver configuration from given config.
 * /*www  . j a v  a  2 s .c  om*/
 * @param configuration The driver config.
 * @throws JSONException On JSON errors.
 */
private void readDriverConfiguration(JSONObject configuration) throws JSONException {
    hubHost = configuration.getString("hubHost");
    hubPort = configuration.getInt("hubPort");
    driverHost = configuration.getString("host");
    driverPort = configuration.getInt("port");
    driverRegistrationEnabled = configuration.getBoolean("register");
    driverMaxSession = configuration.getInt("maxSession");
    mobileAppPath = configuration.getString("autApk");
    mobileTestAppPath = configuration.getString("autTestApk");
    installApksEnabled = configuration.getBoolean("installApks");
    cleanSavedUserDataEnabled = configuration.getBoolean("cleanSavedUserData");
    proxy = configuration.isNull("proxy") ? "org.openqa.grid.selenium.proxy.DefaultRemoteProxy"
            : configuration.getString("proxy");
}

From source file:me.mast3rplan.phantombot.cache.SubscribersCache.java

public int getCount(String channel) throws Exception {
    JSONObject j = TwitchAPIv3.instance().GetChannelSubscriptions(channel, 1, 0, false);

    if (j.getBoolean("_success")) {
        if (j.getInt("_http") == 200) {
            int i = j.getInt("_total");

            return i;
        } else {//from  www .jav a  2  s  . c om
            throw new Exception("[HTTPErrorException] HTTP " + j.getInt("status") + " " + j.getString("error")
                    + ". req=" + j.getString("_type") + " " + j.getString("_url") + " " + j.getString("_post")
                    + "   " + (j.has("message") && !j.isNull("message") ? "message=" + j.getString("message")
                            : "content=" + j.getString("_content")));
        }
    } else {
        throw new Exception("[" + j.getString("_exception") + "] " + j.getString("_exceptionMessage"));
    }
}