Code example for JSONObject

Methods: getInt, getString, isNull

0
     * @return user The new instance of Sample RawContact created from the JSON data. 
     */ 
    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,