Parse使用的中文资料比较少,我翻译了一点内容,大家一起学习!
了解数据类型是学习使用Parse的基础。
Data & Security
数据和安全
Data
数据
Valid Data Types
有效的数据类型
We've designed theParse SDKs so that you typically don't need to worry about how data is savedwhile using the iOS or Android SDKs. Simply add data to the PFObject or ParseObject, and it'll besaved correctly.
Nevertheless,there are some cases where it's useful to be aware of how data is stored on theParse platform.
利用我们设计的ParseSDK,在使用iOSsdk和AndroidSDK的时候,你不需要担心数据是如何存储的。用PFObject或者ParseObject进行数据添加,数据就会被安全的存储起来。
但是有些场合,了解一下Parse平台上数据是如何被存储的只是是非常有用的。
Internally, Parsestores data as JSON, so any datatype that can be converted to JSON can bestored on Parse. The framework can also handle Date, Bytes, and File types. Overall,the following types are allowed for each field in your object:
在Parse平台内部,数据是按照JSON格式来保存的。所以任何类型的数据类型都能被转换为JSON进行存储。Parse的框架也可以处理像日期,字节和文件类型。总之,下面的类型允许你在用来定一个对象的字段类型。
· String字符串
· Number数字
· Boolean布尔类型
· Array数组
· Object对象
· Date日期
· Bytes字节
· File文件
· Null空
The type Object simply denotesthat each value can be composed of nested objects that are JSON-encodable. Keysincluding the characters $ or ., along with thekey __type key, are reservedfor the framework to handle additional types, so don't use those yourself.
Object类型表示变量的值可以由嵌套的对象组成,这些对象是可以基于JSON格式解码的。
包含$ 或 .的键值(key),以及__type这样的键值是保留下来,用于在Parse框架中处理额外的类型的,所以不要用这些类型的值作为键值。
Our SDK handlestranslating native Objective-C and Java types to JSON. For example, if you saveanNSString object, it will be translated into a String type in oursystem.
我们的SDK负责把Objective-c和java类型翻译为Json类型。比如当你保存NSString对象时,它会被转为String类型存入Parse系统。
There are two waysto store binary data. The Bytes type allows you toassociate NSData/bytes[] types directly ona PFObject. This is recommended only for small pieces of binary-encoded data.For actual files (images, documents, etc.), the File type can be usedby instantiating a PFFile/ParseFile and setting it ona field.
这里有两种方式来存储二进制数据数据。Bytes类型允许你直接在PFObject上使用NSData/bytes[]类型。File类型会被实例化为PFfile/ParseFile对象,然后被存储到字段里去。
Data Type Lock-in
数据类型锁定
When a class isinitially created, it doesn't have an inherent schema defined. This means thatfor the first object, it could have any types of fields you want.
当一个Class当初被创建的时候,它不会有一个固有的定义模式。这意味着这个对象可以拥有任何你想要的类型的字段。
However, after afield has been set at least once, that field is locked into the particular typethat was saved. For example, if a User object is savedwith field name of type String, that field willbe restricted to the String type only (our SDKwill return an error if you try to save anything else).
One special caseis that any field can be set to null, no matter whattype it is.
但是,当一个字段一旦被设值之后,这个字段会被锁定为一个具体的类型,不能再改变。例如,User对象中的Name字段被保存为String,那么这个字段就会被限制为String类型了(如果你想保存为其他类型,SDK都会返回错误)。
一个特例是,一个字段如果被设置为null,是无所谓字段是何种类型的。
The Data Browser
数据浏览器
The Data Browseris the web UI where you can update and create objects in each of your apps.Here, you can see the raw JSON values that are saved that represents eachobject in your class.
数据浏览器是一个基于Web UI的,你可以为你的app更新和创建对象。这里你可以看到元生JSON数值会被存储起来,它们就是类(class)中的所有对象的体现和呈现。
When using theinte易做图ce, keep in mind the following:
使用这个交互界面时,请注意下面的内容:
· Entering "null" will setthe value to the special null value, not the string"null".
· 输入"null"时,保存的实际值是null,而不是字符串"null"
· The objectId, createdAt, updatedAt fields cannot be edited (these areset automatically).
· objecdtId,createdAt,updatedAt这些字段不可以编辑,它们会被自动设置。
· The value "(empty)"denotes that the field has not been set for that particular object (this isdifferent than null).
值"(empty)"表示,这个字段还没有被设置为具体的对象。这个和null是有区别的。
Importing Data
导入数据
In addition to theREST api, we also offer data import through CSV or JSON files.
除了REST API,我们提供了从CSV或JSON文件中导入数据的功能。
To create a newclass with data from a CSV or JSON file, go to the Data Browser and click the"Import" button on the left hand column.
为了通过CSV或JSON文件创建一个新的Class,到数据浏览器上,点击左手栏中的导入按钮。
The JSON format isan array of objects in our REST format or a JSON object with a results that contains anarray of objects. In addition to the exposed fields, objects in the Parse Userclass can also have the bcryptPassword field set. Thevalue of this field is a String that is the bcrypthashed password + salt in the modular crypt format described in this StackOverflow answer.Most OpenSSL based bcrypt implementations should have built-in methods toproduce these strings.
JSON格式是一个拥有REST格式的对象的数组,或者是有一个results的JSON对象,results里面包含了一个对象的数组。除了那些暴露出来的字段,Parse的用户类(User Class)中的对象也可以拥有加密密码字段。这个字段是String类型,它的值是基于bcrypt实现的加密算法。很多基于bcrypt 实现的OpenSSL都提供内置的方法来处理这些字符串。
A file containingregular objects could look like:一个包含常规对象的文件看起来如下:
{ “results”: [
{
"score": 1337,
"playerName": "Sean Plott",
"cheatMode": false,
"createdAt": "2012-07-11T20:56:12.347Z",
"updatedAt": "2012-07-11T20:56:12.347Z",
"objectId": "fchpZwSuGG"
}]
}
A file containinga User object could looklike:包含一个User对象的文件看起来如下
{ "results": [{
"username": "cooldude",
"createdAt": "2012-08-27T22:42:30.548Z",
"updatedAt": "2012-09-05T23:23:40.636Z",
"objectId": "ttttSEpfXm",
"sessionToken": "dfwfq3dh0zwe5y2sqv514p4ib",
"bcryptPassword": "$2a$10$ICV5UeEf3lICfnE9W9pN9.O9Ved/ozNo7G83Qbdk5rmyvY8l16MIK"
}]
<