0

您好,我在查询中遇到了一些麻烦。我在 _User 类中创建了一个名为“Empresa”的指针。我知道这个指针是一个 ParseObject。所以我这样做了,我尝试用两种方式来做......

private void queryEmpresa(){
    ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId);
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            for (ParseObject obj:objects
                 ) {

                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();

            }

        }
    });
}

并且...

 private void queryEmpresa(){
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
    query.include("Empresa");
    query.findInBackground(new FindCallback<ParseUser>() {
        @Override
        public void done(List<ParseUser> objects, ParseException e) {
            for (ParseUser obj:objects
                 ) {
                empresa=obj.getParseObject("Empresa");
                String id=empresa.getObjectId();
            }

        }
    });


}

告诉我哪个是正确的代码以及我需要修改什么才能工作。您能否向我解释为什么这不起作用,以便我在不久的将来不会遇到这个问题?

4

1 回答 1

2

试试这个并检查你是否从服务器收到一些错误:

ParseQuery<ParseUser> query = ParseUser.getQuery();
query.include("Empresa");
query.getInBackground(ParseUser.getCurrentUser().getObjectId(), new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your user and you should be able to retrieve Empresa like this
      empresa = object.getParseObject("Empresa");
    } else {
      // something went wrong. It would be good to log.
    }
  }
});
于 2019-05-24T18:58:29.967 回答