1

我想做的是查询一个类并获取一些字符串。但是下面的代码返回类似的东西;

com.parse.ParseObject@b4209180

而且我无法将其恢复为正常的字符串值。

ParseQuery<ParseObject> query = ParseQuery.getQuery("question");
//query.whereKeyExists:@"objectId"
query.whereExists("questionTopic");

query.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> topics, ParseException e) {
        // TODO Auto-generated method stub
        if(e==null){


                textview.setText(topics.toString());

            }


        }else{
             Log.d("notretreive", "Error: " + e.getMessage());
        }


    }
});
4

3 回答 3

1

代码中的“主题”是问题对象的列表。您需要从该对象中获取主题。这应该让你上路:

ParseQuery<ParseObject> query = ParseQuery.getQuery("question");
query.whereExists("questionTopic");

query.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> questions, ParseException e) {
        // The query returns a list of objects from the "questions" class
        if(e==null){
          for (ParseObject question : questions) {
            // Get the questionTopic value from the question object
            Log.d("question", "Topic: " + question.getString("questionTopic");
          }       
        } else {
             Log.d("notretreive", "Error: " + e.getMessage());
        }
    }
});
于 2014-05-15T07:28:33.950 回答
0

API我可以看到该类ParseObject继承toString()自 Object 类。

这意味着除非有自定义 toString() 的实现,否则它将返回该对象的人类可读描述。

在此处检查是否在您的情况下调用了 toString()

编辑:

首先,您尝试通过以下方式在 List 对象上调用 toString()

topics.toString()

您将不得不像这样遍历该列表

for(ParseObject parseObj : topics){
//do something with parseObj like
parseObj.get(<provide_key_here>);
//print to check the value
System.out.println(parseObj.get(<provide_key_here>));
//where key is generally attribute name
}
于 2014-05-15T02:22:10.150 回答
0

I can see this is about two years old. But I am currently having the same issue. SO here is what I did.

You can't just call setText.toString because "topics" is returning as a Parse Object. You need to run a for loop to run through each topics object and get the text from that object, store it in a string and THEN you can set text to string. Here is what I did.

final List questions = new ArrayList<String>();

final ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MasterQuestionList");
query.findInBackground(new FindCallback<ParseObject>() {
  public void done(List<ParseObject> Question, ParseException e) {
    if (e == null) {
      if (Question.size() > 0) {

        for (ParseObject user : Question) {

         String tFile = (String) user.get("Question");
          questions.add(tFile);

        }

        TextView a = (TextView) findViewById(R.id.sentence);
        a.setText(String.valueOf(questions));

I created a list, and added all text values to that list.

Hope this helps anyone running into a similar issue.

于 2017-01-19T22:54:06.790 回答