我使用解析后端存储和检索我的Android应用程序的数据,存储正确完成但我在检索它时遇到问题。我刚刚通过解析文档来检索结果,但我得到的只是0,所有检索到的值...我确定该类存在于具有有效值的解析云中但仍然为所有查询得到0 ..这是我要保存的代码:
Toast.makeText(getApplicationContext(),"writing to parse",Toast.LENGTH_SHORT).show();
ParseObject dataObject = new ParseObject("Score");
dataObject.put("correct",correctAnswers);
dataObject.put("wrong",wrongAnswers);
dataObject.put("percent", percentage);
dataObject.saveInBackground();
这是我如何取回保存的数据
ParseQuery<Score> query = ParseQuery.getQuery("Score");
try {
List<Score> scoreList = query.find();
} catch (ParseException e) {
e.printStackTrace();
}
query = ParseQuery.getQuery("Score");
final Activity ctx = this;
query.findInBackground( new FindCallback<Score>() {
@Override public void done(List<Score> scoreList, ParseException e) {
if ( e == null ) {
ParseObject dataObject = ParseObject.create("Score");
int p = dataObject.getInt("correct");
int q = dataObject.getInt("wrong");
int r = dataObject.getInt("percent");
Toast.makeText(ExamRecordActivity.this,String.valueOf(p),Toast.LENGTH_SHORT).show();
Toast.makeText(ExamRecordActivity.this,String.valueOf(q),Toast.LENGTH_SHORT).show();
Toast.makeText(ExamRecordActivity.this,String.valueOf(r),Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ctx,
"Error updating questions - please make sure you have internet connection",
Toast.LENGTH_LONG).show();
}
}
});
答案 0 :(得分:0)
在done方法中,您正在通过调用ParseObject dataObject = ParseObject.create("Score");
创建一个新的,然后尝试从中读取值而不进行任何操作。
我不知道你的类的结构是什么,但你需要迭代List<Score> scoreList
才能获得查询的数据。