使用ParseObject中的特定值到新查询

时间:2015-11-21 23:11:50

标签: android parse-platform

我正在尝试从relatedGuild获取已发送到其他方法的值ParseObject relationShipObject

我的代码:

private void getRelation(){
    Log.i("Status:", "Retrieving current user...");
    //Retrieve the current logged in user
    ParseUser currentUser = ParseUser.getCurrentUser();

    Log.i("Status:", "Retrieving relationship...");
    //Retrieve the relationship object for currentUser
    ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
    query.whereEqualTo("relatedUser", currentUser);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> relationShip, ParseException e) {
            if (e == null) {
                for (ParseObject relationShipObject : relationShip) {
                    // This does not require a network access.
                    relationshipObject.get("relatedGuild");
                    getGuild(relationShipObject);
                }
            } else {
                Log.d("relation", "Error: " + e.getMessage());
            }
        }
    });
}
private void getGuild(ParseObject relationShipObject){
    Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}

当我在方法Log.d中调用getGuild时,我得到一个等于null的值。我是否试图以错误的方式从行relatedGuild中检索值?如果是,你有解决问题的方法吗?

更新: 当我从getString更改为get("relatedGuild").toString()时,我会得到一个如下所示的值:com.parse.ParseObject@21u702b7。这意味着relationShipObject包含某种我不知道如何检索的值。

1 个答案:

答案 0 :(得分:1)

试试这个:

private void getRelation(){
    Log.i("Status:", "Retrieving current user...");
    //Retrieve the current logged in user
    ParseUser currentUser = ParseUser.getCurrentUser();

    Log.i("Status:", "Retrieving relationship...");
    //Retrieve the relationship object for currentUser
    ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
    query.whereEqualTo("relatedUser", currentUser);
    query.include("relatedGuild");  // <-THIS INCLUDES THE OBJECT BEHIND THE POINTER
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> relationShip, ParseException e) {
            if (e == null) {
                for (ParseObject relationShipObject : relationShip) {
                    // This does not require a network access.
                    relationshipObject.get("relatedGuild");
                    getGuild(relationShipObject);
                }
            } else {
                Log.d("relation", "Error: " + e.getMessage());
            }
        }
    });
}
private void getGuild(ParseObject relationShipObject){
    Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}