Example usage for org.json JSONObject getInt

List of usage examples for org.json JSONObject getInt

Introduction

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

Prototype

public int getInt(String key) throws JSONException 

Source Link

Document

Get the int value associated with a key.

Usage

From source file:jessmchung.groupon.parsers.DivisionParser.java

@Override
public Division parse(JSONObject json) throws JSONException {
    Division obj = new Division();
    if (json.has("lat"))
        obj.setLat(json.getDouble("lat"));
    if (json.has("lng"))
        obj.setLng(json.getDouble("lng"));
    if (json.has("name"))
        obj.setName(json.getString("name"));
    if (json.has("timezone"))
        obj.setTimezone(json.getString("timezone"));
    if (json.has("id"))
        obj.setId(json.getString("id"));
    if (json.has("timezoneOffsetInSeconds"))
        obj.setTimezoneOffsetInSeconds(json.getInt("timezoneOffsetInSeconds"));
    return obj;//from   w w  w  . j a v a  2 s  . c o  m
}

From source file:com.snappy.couchdb.CouchDBHelper.java

/**
 * JSON response from creating a group/*from   w  w  w.  ja v  a2s .c o m*/
 * 
 * @param json
 * @return
 * @throws JSONException 
 */
public static String createGroup(JSONObject json) throws JSONException {

    boolean ok = false;
    String id = null;

    if (json != null) {

        if (json.has(Const.ERROR)) {
            appLogout(null, false, isInvalidToken(json));
            return null;
        }

        ok = json.getInt(Const.OK) == 1 ? true : false;
        id = json.getString(Const.ID);
    }

    if (!ok) {
        Logger.error(TAG + "createGroup", "error in creating a group");
        return null;
    }

    return id;
}

From source file:com.snappy.couchdb.CouchDBHelper.java

/**
 * JSON response from creating a comment
 * //from ww  w  .  ja va2  s.c  o m
 * @param json
 * @return
 * @throws JSONException 
 */
public static String createComment(JSONObject json) throws JSONException {

    boolean ok = false;
    String id = null;

    if (json != null) {

        if (json.has(Const.ERROR)) {
            appLogout(null, false, isInvalidToken(json));
            return null;
        }

        ok = json.getInt(Const.OK) == 1 ? true : false;
        id = json.getString(Const.ID);
    }

    if (!ok) {
        Logger.error(TAG + "createComment", "error in creating comment");
        return null;
    }

    return id;
}

From source file:com.snappy.couchdb.CouchDBHelper.java

/**
 * JSON response from updating a group you own
 * //w  w  w.  j  a va2s  .c  o  m
 * @param json
 * @return
 * @throws JSONException 
 */
public static boolean updateGroup(JSONObject json) throws JSONException {

    boolean ok = false;

    if (json != null) {

        if (json.has(Const.ERROR)) {
            appLogout(false, false, isInvalidToken(json));
            return false;
        }

        ok = json.getInt(Const.OK) == 1 ? true : false;

        /* Important */
        UsersManagement.getToGroup().setRev(json.getString(Const.REV));
    }

    if (!ok) {
        Logger.error(TAG + "updateGroup", "error in updating a group");
    }

    return ok;
}

From source file:com.snappy.couchdb.CouchDBHelper.java

public static List<Member> parseMemberObjects(JSONObject jsonData) throws JSONException {
    // Get total member
    int totalMember = jsonData.getInt("count");
    Member.setTotalMember(totalMember);

    // Get list member
    List<Member> listMembers = null;
    JSONArray jsonArray = jsonData.getJSONArray("users");
    if (jsonArray != null) {
        listMembers = new ArrayList<Member>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject row = jsonArray.getJSONObject(i);
            try {
                String id = row.getString("_id");
                String name = row.getString("name");
                String image = row.getString("avatar_thumb_file_id");
                String online = row.getString("online_status");
                Member member = new Member(id, name, image, online);
                listMembers.add(member);
            } catch (JSONException e) {
            }//from w  w  w .  ja  v a 2s . c o  m
        }
    }

    return listMembers;
}

From source file:com.snappy.couchdb.CouchDBHelper.java

/**
 * /*  ww w  .j a  va  2s . co  m*/
 * @param json
 * @return
 * @throws JSONException 
 */
public static int getCommentCount(JSONObject json) throws JSONException {

    int count = 0;

    if (json != null) {

        if (json.has(Const.ERROR)) {
            appLogout(null, false, isInvalidToken(json));
            return 0;
        }

        JSONArray rows = json.getJSONArray(Const.ROWS);

        for (int i = 0; i < rows.length(); i++) {

            JSONObject row = rows.getJSONObject(i);
            count = row.getInt(Const.VALUE);

        }
    }

    return count;
}

From source file:com.snappy.couchdb.CouchDBHelper.java

/**
 * Parse a single JSON object of Message type
 * // w w w  .j a  v a  2 s.  co m
 * @param json
 * @param image
 * @param voice
 * @return
 * @throws SpikaException 
 * @throws JSONException 
 * @throws IOException 
 * @throws ClientProtocolException 
 */
private static Message parseMessageObject(JSONObject json, boolean image, boolean voice, boolean video)
        throws ClientProtocolException, IOException, JSONException, SpikaException {

    Message message = new Message();

    if (json == null) {
        return message;
    }

    if (json.has(Const.ERROR)) {
        appLogout(null, false, isInvalidToken(json));
        return null;
    }

    try {
        message.setId(json.getString(Const._ID));
    } catch (JSONException e) {
        message.setId("");
    }

    try {
        message.setRev(json.getString(Const._REV));
    } catch (JSONException e) {
        message.setRev("");
    }

    try {
        message.setType(json.getString(Const.TYPE));
    } catch (JSONException e) {
        message.setType("");
    }

    try {
        message.setMessageType(json.getString(Const.MESSAGE_TYPE));
    } catch (JSONException e) {
        message.setMessageType("");
    }

    try {
        message.setMessageTargetType(json.getString(Const.MESSAGE_TARGET_TYPE));
    } catch (JSONException e) {
        message.setMessageTargetType("");
    }

    try {
        message.setBody(json.getString(Const.BODY));
    } catch (JSONException e) {
        message.setBody("");
    }

    try {
        message.setFromUserId(json.getString(Const.FROM_USER_ID));
    } catch (JSONException e) {
        message.setFromUserId("");
    }

    try {
        message.setFromUserName(json.getString(Const.FROM_USER_NAME));
    } catch (JSONException e) {
        message.setFromUserName("");
    }

    try {
        message.setToUserId(json.getString(Const.TO_USER_ID));
    } catch (JSONException e) {
        message.setToUserId("");
    }

    try {
        message.setToGroupName(json.getString(Const.TO_USER_NAME));
    } catch (JSONException e) {
        message.setToGroupName("");
    }

    try {
        message.setToGroupId(json.getString(Const.TO_GROUP_ID));
    } catch (JSONException e) {
        message.setToGroupId("");
    }

    try {
        message.setToGroupName(json.getString(Const.TO_GROUP_NAME));
    } catch (JSONException e) {
        message.setToGroupName("");
    }

    try {
        message.setCreated(json.getLong(Const.CREATED));
    } catch (JSONException e) {
        return null;
    }

    try {
        message.setModified(json.getLong(Const.MODIFIED));
    } catch (JSONException e) {
        return null;
    }

    try {
        message.setValid(json.getBoolean(Const.VALID));
    } catch (JSONException e) {
        message.setValid(true);
    }

    try {
        message.setAttachments(json.getJSONObject(Const.ATTACHMENTS).toString());
    } catch (JSONException e) {
        message.setAttachments("");
    }

    try {
        message.setLatitude(json.getString(Const.LATITUDE));
    } catch (JSONException e) {
        message.setLatitude("");
    }

    try {
        message.setLongitude(json.getString(Const.LONGITUDE));
    } catch (JSONException e) {
        message.setLongitude("");
    }

    try {
        message.setImageFileId((json.getString(Const.PICTURE_FILE_ID)));
    } catch (JSONException e) {
        message.setImageFileId("");
    }

    try {
        message.setImageThumbFileId((json.getString(Const.PICTURE_THUMB_FILE_ID)));
    } catch (JSONException e) {
        message.setImageThumbFileId("");
    }

    try {
        message.setVideoFileId((json.getString(Const.VIDEO_FILE_ID)));
    } catch (JSONException e) {
        message.setVideoFileId("");
    }

    try {
        message.setVoiceFileId((json.getString(Const.VOICE_FILE_ID)));
    } catch (JSONException e) {
        message.setVoiceFileId("");
    }

    try {
        message.setEmoticonImageUrl(json.getString(Const.EMOTICON_IMAGE_URL));
    } catch (JSONException e) {
        message.setEmoticonImageUrl("");
    }

    try {
        message.setAvatarFileId(json.getString(Const.AVATAR_THUMB_FILE_ID));
    } catch (JSONException e) {
        message.setAvatarFileId("");
    }

    try {
        message.setDeleteType(json.getInt(Const.DELETE_TYPE));
    } catch (JSONException e) {
        message.setDeleteType(0);
    }

    try {
        message.setDelete(json.getInt(Const.DELETE_AT));
    } catch (JSONException e) {
        message.setDelete(0);
    }

    try {
        message.setReadAt(json.getInt(Const.READ_AT));
    } catch (JSONException e) {
        message.setReadAt(0);
    }

    try {
        message.setCommentCount(json.getInt(Const.COMMENT_COUNT));
    } catch (JSONException e) {
        message.setCommentCount(0);
    }

    //      if (image || video || voice) {
    //         message.setCommentCount(CouchDB.getCommentCount(message.getId()));
    //      }

    return message;
}

From source file:com.mercandalli.android.apps.files.main.Config.java

private void load(final Context context) {
    final String fileContent = FileUtils.readStringFile(context, FILE_NAME);
    if (fileContent == null) {
        return;/*from w  ww .  jav  a 2  s  .  co  m*/
    }
    try {
        JSONObject tmpJson = new JSONObject(fileContent);
        if (tmpJson.has("settings_1")) {
            JSONObject tmpSettings1 = tmpJson.getJSONObject("settings_1");
            for (ENUM_Int enum_int : ENUM_Int.values()) {
                if (tmpSettings1.has(enum_int.key)) {
                    enum_int.value = tmpSettings1.getInt(enum_int.key);
                }
            }
            for (ENUM_Boolean enum_boolean : ENUM_Boolean.values()) {
                if (tmpSettings1.has(enum_boolean.key)) {
                    enum_boolean.value = tmpSettings1.getBoolean(enum_boolean.key);
                }
            }
            for (ENUM_String enum_string : ENUM_String.values()) {
                if (tmpSettings1.has(enum_string.key)) {
                    enum_string.value = tmpSettings1.getString(enum_string.key);
                }
            }
        }
    } catch (JSONException e) {
        Log.e(getClass().getName(), "Failed to convert Json", e);
    }
}

From source file:fr.pasteque.pos.customers.CustomerInfoExt.java

public CustomerInfoExt(JSONObject o) {
    super(null);//  w w w.ja v  a  2  s . c  o  m
    if (!o.isNull("id")) {
        this.id = o.getString("id");
    }
    if (!o.isNull("number")) {
        this.taxid = o.getString("number");
    }
    if (!o.isNull("dispName")) {
        this.name = o.getString("dispName");
    }
    if (!o.isNull("key")) {
        this.searchkey = o.getString("key");
    }
    if (!o.isNull("custTaxId")) {
        this.taxcustomerid = o.getString("custTaxId");
    }
    if (!o.isNull("discountProfileId")) {
        this.discountProfileId = o.getInt("discountProfileId");
    }
    if (!o.isNull("notes")) {
        this.notes = o.getString("notes");
    }
    this.visible = o.getBoolean("visible");
    if (!o.isNull("card")) {
        this.card = o.getString("card");
    }
    if (!o.isNull("maxDebt")) {
        this.maxdebt = o.getDouble("maxDebt");
    }
    if (!o.isNull("debtDate")) {
        this.curdate = DateUtils.readSecTimestamp(o.getLong("debtDate"));
    }
    if (!o.isNull("currDebt")) {
        this.curdebt = o.getDouble("currDebt");
    }
    this.prepaid = o.getDouble("prepaid");
    if (!o.isNull("firstName")) {
        this.firstname = o.getString("firstName");
    }
    if (!o.isNull("lastName")) {
        this.lastname = o.getString("lastName");
    }
    if (!o.isNull("email")) {
        this.email = o.getString("email");
    }
    if (!o.isNull("phone1")) {
        this.phone = o.getString("phone1");
    }
    if (!o.isNull("phone2")) {
        this.phone2 = o.getString("phone2");
    }
    if (!o.isNull("fax")) {
        this.fax = o.getString("fax");
    }
    if (!o.isNull("addr1")) {
        this.address = o.getString("addr1");
    }
    if (!o.isNull("addr2")) {
        this.address2 = o.getString("addr2");
    }
    if (!o.isNull("zipCode")) {
        this.postal = o.getString("zipCode");
    }
    if (!o.isNull("city")) {
        this.city = o.getString("city");
    }
    if (!o.isNull("region")) {
        this.region = o.getString("region");
    }
    if (!o.isNull("country")) {
        this.country = o.getString("country");
    }
}

From source file:com.chess.genesis.dialog.GameStatsDialog.java

public GameStatsDialog(final Context context, final JSONObject json) {
    super(context, BaseDialog.CANCEL);

    String[] statusArr = null;//w ww.  ja v a 2 s  .c  om
    String gametype = null, gameid = null, sign = null;
    int eventtype = 0, ycol = 0, w_from = 0, w_to = 0, b_from = 0, b_to = 0;

    try {
        gameid = json.getString("gameid");
        ycol = json.getInt("yourcolor");
        statusArr = STATUS_MAP.get(json.getInt("status") * ycol);
        gametype = json.getString("gametype");
        gametype = gametype.substring(0, 1).toUpperCase(Locale.US) + gametype.substring(1);
        eventtype = Integer.parseInt(json.getString("eventtype"));

        if (ycol == Piece.WHITE)
            opponent = json.getString("black_name");
        else
            opponent = json.getString("white_name");

        if (eventtype != Enums.INVITE) {
            w_from = json.getJSONObject("white").getInt("from");
            w_to = json.getJSONObject("white").getInt("to");

            b_from = json.getJSONObject("black").getInt("from");
            b_to = json.getJSONObject("black").getInt("to");
        }
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    final int to = (ycol == Piece.WHITE) ? w_to : b_to;
    diff = (ycol == Piece.WHITE) ? (w_to - w_from) : (b_to - b_from);
    sign = (diff >= 0) ? "+" : "-";

    title = statusArr[0];
    result = statusArr[1];
    psr_type = gametype + " PSR :";

    if (eventtype == Enums.INVITE)
        psr_score = "None (Invite Game)";
    else
        psr_score = sign + String.valueOf(Math.abs(diff)) + " (" + String.valueOf(to) + ')';

    final GameDataDB db = new GameDataDB(context);
    db.archiveNetworkGame(gameid, w_from, w_to, b_from, b_to);
    db.close();
}