- DocumentDB 教程
- DocumentDB - 首页
- DocumentDB - 简介
- DocumentDB - 优势
- DocumentDB - 环境设置
- DocumentDB - 创建账户
- DocumentDB - 连接账户
- DocumentDB - 创建数据库
- DocumentDB - 列出数据库
- DocumentDB - 删除数据库
- DocumentDB - 创建集合
- DocumentDB - 删除集合
- DocumentDB - 插入文档
- DocumentDB - 查询文档
- DocumentDB - 更新文档
- DocumentDB - 删除文档
- DocumentDB - 数据建模
- DocumentDB - 数据类型
- DocumentDB - 限制记录
- DocumentDB - 排序记录
- DocumentDB - 索引记录
- DocumentDB - 地理空间数据
- DocumentDB - 分区
- DocumentDB - 数据迁移
- DocumentDB - 访问控制
- DocumentDB - 数据可视化
- DocumentDB 有用资源
- DocumentDB - 快速指南
- DocumentDB - 有用资源
- DocumentDB - 讨论
DocumentDB - 数据类型
JSON(JavaScript 对象表示法)是一种轻量级的基于文本的开放标准,旨在用于人类可读的数据交换,并且易于机器解析和生成。JSON 是 DocumentDB 的核心。我们通过网络传输 JSON,将 JSON 存储为 JSON,并索引 JSON 树,从而允许对完整的 JSON 文档进行查询。
JSON 格式支持以下数据类型:
| 序号 | 类型和描述 |
|---|---|
| 1 | 数字 JavaScript 中的双精度浮点数格式 |
| 2 | 字符串 带反斜杠转义的双引号 Unicode 字符串 |
| 3 | 布尔值 真或假 |
| 4 | 数组 一个有序的值序列 |
| 5 | 值 它可以是字符串、数字、true 或 false、null 等。 |
| 6 | 对象 一个无序的键值对集合 |
| 7 | 空格 它可以在任何一对标记之间使用 |
| 8 | 空值 空 |
让我们来看一个简单的 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/"
}
Created document 1001 from typed object
广告