本文整理汇总了C#中Contact.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.ToJson方法的具体用法?C# Contact.ToJson怎么用?C# Contact.ToJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contact
的用法示例。
在下文中一共展示了Contact.ToJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public void Serialize()
{
var contact = new Contact
{
LastName = "Rocha",
FirstName = "Luis",
Salutation = "Mr.",
Phone = "(512) 757-6000",
};
var jsonRequest = contact.ToJson();
Assert.AreEqual("{\n \"LastName\": \"Rocha\",\n \"FirstName\": \"Luis\",\n \"Salutation\": \"Mr.\",\n \"Phone\": \"(512) 757-6000\"\n}", jsonRequest.Replace("\r",""));
}
示例2: SerializeIncludesOnlyNonNullAndUpdatableProperties
public void SerializeIncludesOnlyNonNullAndUpdatableProperties()
{
var contact = new Contact
{
Id = "003i000000W2RMDAA3",
LastName = "Rocha",
FirstName = "Luis",
Salutation = "Mr.",
Name = "Luis Rocha",
Phone = "(512) 757-6000",
CreatedDate = "2014-01-04T23:45:29.000+0000",
CreatedById = "005i0000002OPr5AAG",
LastModifiedDate = "2014-02-16T18:30:03.000+0000",
LastModifiedById = "005i0000002OPr5AAG",
SystemModstamp = "2014-02-16T18:30:03.000+0000"
};
var jsonRequest = contact.ToJson();
// Assert that updatable and non null properties are serialized.
Assert.AreEqual("{\n \"LastName\": \"Rocha\",\n \"FirstName\": \"Luis\",\n \"Salutation\": \"Mr.\",\n \"Phone\": \"(512) 757-6000\"\n}", jsonRequest.Replace("\r",""));
}