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.prx.prp.utility.ParsedJSONObject.java

public ParsedJSONObject(JSONObject object, String[] columnNames) {
    int index;//from  w w  w  . j  a v a  2s.c  o  m
    names = columnNames;
    values = new String[columnNames.length];
    for (index = 0; index < columnNames.length; index++) {
        try {
            values[index] = object.getString(columnNames[index]);
        } catch (JSONException e) {
            values[index] = "NULL";
        }
    }
    storeId(object);
    checkForDelete(object);
}

From source file:com.whizzosoftware.hobson.rest.v1.resource.presence.PresenceEntitiesResource.java

/**
 * @api {post} /api/v1/users/:userId/hubs/:hubId/presence/entities Add presence entity
 * @apiVersion 0.1.3/*from   ww  w  .j a v a 2  s . c o  m*/
 * @apiName AddPresenceEntity
 * @apiDescription Adds a new presence entity.
 * @apiGroup Presence
 *
 * @apiExample {json} Example Request:
 * {
 *   "name": "Jane's Car",
 *   "location": null
 * }
 * @apiSuccessExample Success Response:
 * HTTP/1.1 202 Accepted
 */
@Override
protected Representation post(Representation entity) {
    HobsonRestContext ctx = HobsonRestContext.createContext(this, getRequest());
    JSONObject json = JSONMarshaller.createJSONFromRepresentation(entity);
    presenceManager.addEntity(ctx.getUserId(), ctx.getHubId(),
            new PresenceEntity(json.getString("name"), json.getString("location")));
    getResponse().setStatus(Status.SUCCESS_ACCEPTED);
    return new EmptyRepresentation();
}

From source file:de.btobastian.javacord.utils.handler.message.MessageDeleteHandler.java

@Override
public void handle(JSONObject packet) {
    String messageId = packet.getString("id");
    final Message message = api.getMessageById(messageId);
    if (message == null) {
        return; // no cached version available
    }//from w w w  . j a va  2 s.c  o  m
    synchronized (message) {
        if (message.isDeleted()) {
            return; // already called listener
        } else {
            ((ImplMessage) message).setDeleted(true);
        }
    }
    listenerExecutorService.submit(new Runnable() {
        @Override
        public void run() {
            List<MessageDeleteListener> listeners = api.getListeners(MessageDeleteListener.class);
            synchronized (listeners) {
                for (MessageDeleteListener listener : listeners) {
                    try {
                        listener.onMessageDelete(api, message);
                    } catch (Throwable t) {
                        logger.warn("Uncaught exception in MessageDeleteListener!", t);
                    }
                }
            }
        }
    });
}

From source file:org.rapidandroid.activity.FormCreator.java

@Override
protected synchronized void onResume() {
    super.onResume();

    Intent intent = getIntent();/*from www  .  j  a  v a2  s.c  om*/
    String currentForm = intent.getStringExtra("current_form");
    if (currentForm != null) {
        try {
            String contents = new String(currentForm);
            JSONObject readobject = new JSONObject(contents);

            EditText etxFormName = (EditText) findViewById(R.id.etx_formname);
            EditText etxFormPrefix = (EditText) findViewById(R.id.etx_formprefix);
            EditText etxDescription = (EditText) findViewById(R.id.etx_description);

            etxFormName.setText(readobject.getString(STATE_FORMNAME));
            etxFormPrefix.setText(readobject.getString(STATE_PREFIX));
            etxDescription.setText(readobject.getString(STATE_DESC));
            boolean checkForFields = true;
            int i = 0;
            do {
                checkForFields = readobject.has("Field" + i);
                if (checkForFields) {
                    JSONObject fieldBundle = (JSONObject) readobject.get("Field" + i);
                    restoreFieldFromState(fieldBundle);
                    i++;
                }
            } while (checkForFields);
        } catch (Exception e) {
            Log.e("FOOBAR", e.getMessage(), e);
        }
    }
}

From source file:org.rapidandroid.activity.FormCreator.java

private void restoreFieldFromState(JSONObject fieldjson) {
    if (mCurrentFields == null) {
        mCurrentFields = new ArrayList<Field>();
    }//from  w w  w .  j a  va  2  s.  c o  m
    try {
        Field newField = new Field();
        newField.setFieldId(-1);
        newField.setName(fieldjson.getString(ResultConstants.RESULT_KEY_FIELDNAME));
        newField.setDescription(fieldjson.getString(ResultConstants.RESULT_KEY_DESCRIPTION));
        int fieldTypeID = fieldjson.getInt(ResultConstants.RESULT_KEY_FIELDTYPE_ID);
        ITokenParser fieldtype = ModelTranslator.getFieldType(fieldTypeID);
        newField.setFieldType(fieldtype);

        int listSize = mCurrentFields.size();

        for (int i = 0; i < listSize; i++) {
            Field existingField = mCurrentFields.get(i);
            if (existingField.getName().equals(newField.getName())) {
                return;
            }
        }
        if (listSize > 0) {
            listSize = listSize - 1;
        }
        newField.setSequenceId(listSize);

        mCurrentFields.add(newField);

        fieldViewAdapter.notifyDataSetChanged();
        // updateFieldList();
    } catch (Exception ex) {
        Log.d("FormCreator", ex.getMessage());
    }
}

From source file:net.jmhertlein.mcanalytics.api.request.PasswordResetRequest.java

@Override
public Boolean processResponse(JSONObject response) {
    return response.getString("status").equals("OK");
}

From source file:com.moarub.kipptapi.KipptAPIToken.java

@Override
protected void onPostExecute(StringBuilder builder) {
    if (builder == null) {
        return;//from   w w  w  . j a v  a2  s.c  o m
    }

    try {
        JSONObject jobj = (JSONObject) new JSONTokener(builder.toString()).nextValue();
        fToken = jobj.getString("api_token");
        setUserName(jobj.getString("username"));
    } catch (JSONException e) {
        Log.d("ApiTokenFailure", "Can't fetch API Token (Broken JSON) " + e.getMessage());
        fListener.setAPIToken(false);
        return;
    }
    Log.d("Result", fToken);
    fListener.setAPIToken(true);
}

From source file:net.chunkyhosting.Roe.computer.CHGManager.gui.panels.ServerDisplay.java

public ServerDisplay(JSONObject server) {

    JLabel game = new JLabel(server.getString("gametype"));
    JLabel statusImg = new JLabel(
            new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                    + File.separator + "img" + File.separator + "icons" + File.separator + "ball_green.gif"));
    JLabel statusDetail = new JLabel("284/500");
    JLabel ip = new JLabel(server.getString("ip") + ":" + server.getString("port"));
    JButton console = new JButton(
            new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                    + File.separator + "img" + File.separator + "icons" + File.separator + "console.gif"));
    JButton restart = new JButton(
            new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                    + File.separator + "img" + File.separator + "icons" + File.separator + "restart.gif"));
    JButton stop = new JButton(
            new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                    + File.separator + "img" + File.separator + "icons" + File.separator + "stop.gif"));
    JButton edit = new JButton(
            new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                    + File.separator + "img" + File.separator + "icons" + File.separator + "edit.gif"));
    GroupLayout gl_panel = new GroupLayout(this);
    gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_panel.createSequentialGroup().addContainerGap().addComponent(game).addGap(18)
                    .addComponent(statusImg).addGap(18).addComponent(statusDetail).addGap(18).addComponent(ip)
                    .addPreferredGap(ComponentPlacement.RELATED, 178, Short.MAX_VALUE).addComponent(console)
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(restart)
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(stop)
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(edit)));
    gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_panel.createSequentialGroup().addContainerGap()
                    .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(edit)
                            .addComponent(stop).addComponent(restart).addComponent(console))
                    .addContainerGap(23, Short.MAX_VALUE))
            .addGroup(Alignment.TRAILING,
                    gl_panel.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE)
                            .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(game)
                                    .addComponent(statusImg).addComponent(statusDetail).addComponent(ip))
                            .addGap(14)));
    this.setLayout(gl_panel);

}

From source file:com.joyfulmongo.db.ContainerObjectDate.java

@Override
public void onQuery(String collectionName, JSONObject theChild) {
    JSONObject childJson = theChild.getJSONObject(key);

    String iso = childJson.getString("iso");

    try {//from  w  w  w  .  ja v a 2 s . c  o m
        Date date = Utils.getParseDateFormat().parse(iso);
        theChild.put(key, date);
    } catch (ParseException e) {
        // do nothing
        LOGGER.log(Level.WARNING, "Wrong format of date string, skip convert.");
    }

}

From source file:com.daskiworks.ghwatch.backend.AuthenticationManager.java

private String remoteLogin(Context context, GHCredentials cred, String otp)
        throws JSONException, NoRouteToHostException, AuthenticationException, ClientProtocolException,
        URISyntaxException, IOException {
    Map<String, String> headers = null;
    otp = Utils.trimToNull(otp);//from w  w  w.  j ava  2  s  .  co  m
    if (otp != null) {
        headers = new HashMap<String, String>();
        headers.put("X-GitHub-OTP", otp);
    }
    Response<String> resp = RemoteSystemClient.putToURL(context, cred, GH_AUTH_REQ_URL, headers,
            GH_AUTH_REQ_CONTENT);
    JSONObject jo = new JSONObject(resp.data);
    return jo.getString("token");
}