本文整理汇总了C#中System.Collections.Generic.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.ToJson方法的具体用法?C# System.Collections.Generic.ToJson怎么用?C# System.Collections.Generic.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.ToJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportBlocks
public void ImportBlocks()
{
var obj = new
{
IsSystem = false,
Path = "Test Path",
Name = "Test Name",
Description = "Test desc",
Blocks = new List<dynamic>
{
new {
IsSystem = true,
BlockTypeId = 1,
Zone = "TestZone",
Order = 3,
Name = "FooInstance",
OutputCacheDuration = 0
}
}
};
var json = obj.ToJson();
var blockType = BlockType.FromJson( json );
var blocks = blockType.Blocks;
Assert.NotNull( blockType );
// TODO: Fix Clone() to include all child objects
//Assert.NotNull( blocks );
//Assert.NotEmpty( blocks );
//Assert.Equal( blocks.First().Name, obj.Blocks[0].Name );
}
示例2: BuildRequest
public override HttpRequestItem BuildRequest()
{
var url = string.Format(ApiUrls.GetContact, Session.BaseUrl, Session.PassTicket, Session.Skey, Timestamp);
var obj = new { Session.BaseRequest };
var req = new HttpRequestItem(HttpMethodType.Post, url)
{
RawData = obj.ToJson(),
ContentType = HttpConstants.JsonContentType
};
return req;
}
示例3: Can_parse_ArrayObjects
public void Can_parse_ArrayObjects()
{
var data = new { key = new[] { "value1", "value2" } };
var json = data.ToJson();
Assert.That(json, Is.EqualTo(@"{""key"":[""value1"",""value2""]}"));
var value = JsonObject.Parse(json);
var dataObjects = value.Get<string[]>("key");
Assert.That(dataObjects[0], Is.EqualTo("value1"));
Assert.That(dataObjects[1], Is.EqualTo("value2"));
}
示例4: ShouldImportProperties
public void ShouldImportProperties()
{
var obj = new
{
IsSystem = false,
Path = "Test Path",
Name = "Test Name",
Description = "Test desc"
};
var json = obj.ToJson();
var blockType = BlockType.FromJson( json );
Assert.AreEqual( obj.Description, blockType.Description );
Assert.AreEqual( obj.IsSystem, blockType.IsSystem );
}