简体   繁体   English

从解析中检索数据

[英]Retrieving a data from Parse

I'd like to get a String which is in an Object in Parse without the something.put("blalala")... . 我想得到一个没有something.put("blalala")...解析Object中的字符串。

Only by taking the string from Parse. 仅从Parse中获取字符串。 What's wrong with my code ? 我的代码有什么问题? How can I do that ? 我怎样才能做到这一点 ?

public class MyActivity extends Activity {


TextView textView;

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    Parse.initialize(this, "blablablbalba", "blablablabla");

    final ParseObject gameScore = new ParseObject("GameScore");

     //txtv
     textView = (TextView)findViewById(R.id.textView);
     //txtv


     ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");

     query.getInBackground("theid", new GetCallback<ParseObject>() {
         @Override
         public void done(ParseObject parseObject, com.parse.ParseException e) {
             if (e == null){

                 String playerName = gameScore.getString("playerName");
                 textView.setText(playerName);

             }
             else {
                 textView.setText("Mince !!!");
             }
         }
     });







 }

} }

The code should read String playerName = parseObject.getString("playerName"); 该代码应读取String playerName = parseObject.getString("playerName"); parseObject is the variable that's holding the result from the query, not the gameScore variable parseObject是保存查询结果的变量,而不是gameScore变量

(EDIT:)Straight from the docs: (编辑:)直接来自文档:

    ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM