JSON或JavaScript Object Notation是一种基于文本的轻量级开放标准,专为人类可读的数据交换而设计,也易于机器解析和生成. JSON是DocumentDB的核心.我们通过线路传输JSON,我们将JSON存储为JSON,并且我们索引JSON树,允许查询完整的JSON文档.
JSON格式支持以下数据类型 :
S.No. | Type & Description |
---|---|
1 | Number Double-precision floating-point format in JavaScript |
2 | String Double-quoted Unicode with backslash escaping |
3 | Boolean True or false |
4 | Array An ordered sequence of values |
5 | Value It can be a string, a number, true or false, null, etc. |
6 | Object An unordered collection of key:value pairs |
7 | Whitespace It can be used between any pair of tokens |
8 | Null Empty |
让我们看一个简单的DateTime类型示例.将出生日期添加到客户类.
public class Customer { [JsonProperty(PropertyName = "id")] public string Id { get; set; } // Must be nullable, unless generating unique values for new customers on client [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "address")] public Address Address { get; set; } [JsonProperty(PropertyName = "birthDate")] public DateTime BirthDate { get; set; } }
我们可以使用DateTime进行存储,检索和查询,如下面的代码所示.
private async static Task CreateDocuments(DocumentClient client) { Console.WriteLine(); Console.WriteLine("**** Create Documents ****"); Console.WriteLine(); var document3Definition = new Customer { Id = "1001", Name = "Luke Andrew", Address = new Address { AddressType = "Main Office", AddressLine1 = "123 Main Street", Location = new Location { City = "Brooklyn", StateProvinceName = "New York" }, PostalCode = "11229", CountryRegionName = "United States" }, BirthDate = DateTime.Parse(DateTime.Today.ToString()), }; Document document3 = await CreateDocument(client, document3Definition); Console.WriteLine("Created document {0} from typed object", document3.Id); Console.WriteLine(); }
当编译并执行上述代码并创建文档时,您将看到现在添加了出生日期.
**** Create Documents **** Created new document: 1001 { "id": "1001", "name": "Luke Andrew", "address": { "addressType": "Main Office", "addressLine1": "123 Main Street", "location": { "city": "Brooklyn", "stateProvinceName": "New York" }, "postalCode": "11229", "countryRegionName": "United States" }, "birthDate": "2015-12-14T00:00:00", "_rid": "Ic8LAMEUVgAKAAAAAAAAAA==", "_ts": 1450113676, "_self": "dbs/Ic8LAA==/colls/Ic8LAMEUVgA=/docs/Ic8LAMEUVgAKAAAAAAAAAA==/", "_etag": "00002d00-0000-0000-0000-566efa8c0000", "_attachments": "attachments/" } 创建文件1001来回m typed object
S.No. | Type&说明 |
---|---|
1 | 数字 JavaScript中的双精度浮点格式 |
2 | 字符串 双引号Unicode,反斜杠转义 |
3 | 布尔 是或否 |
4 | 数组 有序的值序列 |
5 | 价值 它可以是一个字符串,一个数字, true或false,null等. |
6 | 对象 密钥:值对的无序集合 |
7 | 空白 它可用于任何一对令牌 |
8 | 空 空 |