从Parse.com中的类中检索数据

时间:2015-07-08 20:14:23

标签: android database parse-platform

我在Parse.com上有一个班级,如XYZ,它有电子邮件,密码,电话,年龄。我有电子邮件和密码组合,我想检查班级中是否有这样的组合?我该怎么做?

我有一个Donate课程,我收到了一封电子邮件(e)和密码(pw)。这是代码:

`ParseQuery<ParseObject> query = ParseQuery.getQuery("donate");
            query.whereEqualTo("email", e);
            query.whereEqualTo("password", pw);
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> list, ParseException e) {
                    if (e == null) {
                        Toast.makeText(getApplicationContext(), "Success!!!", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(getApplicationContext(), "Something went wrong!!!", Toast.LENGTH_LONG).show();
                    }
                }
            });                     `            

这总能显示出“成功”。不论字符串e和pw如何。

1 个答案:

答案 0 :(得分:0)

只要有技术问题调用服务器,

ParseQuery 就会返回 ParseException 。 否则,即使您的查询找不到您要查找的内容, 它将返回空列表&#39; e&#39; var null 。 所以你需要做的是:

    ParseQuery<ParseObject> query = ParseQuery.getQuery("donate");
    query.whereEqualTo("email", e);
    query.whereEqualTo("password", pw);
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
                if (list.isEmpty() == false) {   // add this
                    Toast.makeText(getApplicationContext(), "Success!!!", Toast.LENGTH_LONG).show(); 
                }else{
                    Toast.makeText(getApplicationContext(), "Worng password!!!", Toast.LENGTH_LONG).show(); // add this

                }

            } else {
                Toast.makeText(getApplicationContext(), "Something went wrong!!!", Toast.LENGTH_LONG).show();
            }
        }
    });