Documentdb-data-types
提供:Dev Guides
DocumentDB-データ型
JSONまたはJavaScript Object Notationは、人間が読めるデータ交換用に設計された軽量のテキストベースのオープンスタンダードであり、マシンが解析および生成するのも簡単です。 JSONはDocumentDBの中心です。 JSONをネットワーク経由で送信し、JSONをJSONとして保存し、JSONツリーにインデックスを付けて、完全なJSONドキュメントでクエリを実行できるようにします。
JSON形式は次のデータ型をサポートしています-
S.No. | Type & Description |
---|---|
1 |
Number JavaScriptの倍精度浮動小数点形式 |
2 |
String バックスラッシュをエスケープする二重引用符付きUnicode |
3 |
Boolean 正しいか間違っているか |
4 |
Array 値の順序付けられたシーケンス |
5 |
Value 文字列、数値、trueまたはfalse、nullなどを指定できます。 |
6 |
Object キーと値のペアの順不同のコレクション |
7 |
Whitespace トークンの任意のペア間で使用できます |
8 |
Null 空の |
単純な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