凉鞋学 Parse Android Guide(二) 面向 Android 的Parse 云服务

来源:互联网 发布:linux中cat命令 编辑:程序博客网 时间:2024/04/27 16:51

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Saving Objects(保存对象)

Let's say you want to save the GameScore described above to the Parse Cloud. The interface is similar to a Map, plus thesaveInBackground method:


(如果你想把上面描述过的GameScore存在Parse云上,要使用的接口和Java中的Map很类似,要在后面加上saveInBackground方法,如下图所示)

ParseObject gameScore = newParseObject("GameScore");
gameScore.put("score",1337);
gameScore.put("playerName","Sean Plott");
gameScore.put("cheatMode",false);
gameScore.saveInBackground();

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


After this code runs, you will probably be wondering if anything really happened. To make sure the data was saved, you can look at the Data Browser in your app on Parse. You should see something like this:


(以上这段代码运行后,你可能会想知道到底发生了什么。为了确保数据被存储,你可以查看Data Browser。)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------



objectId: "xWMyZ4YEGZ",score:1337,playerName: "Sean Plott", cheatMode:false,
createdAt:"2011-06-10T18:33:42Z",updatedAt:"2011-06-10T18:33:42Z"

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------



There are two things to note here. You didn't have to configure or set up a new Class called GameScore before running this code. Your Parse app lazily creates this Class for you when it first encounters it.

(到这里要注意两件事:

1、你不需要再次声明新的GameScore类。

2、仪表板会为你第一次传送的对象创建一个类。

)


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------