当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.ToJson方法代码示例

本文整理汇总了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 );
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:30,代码来源:BlockTypeTests.cs

示例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;
 }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:11,代码来源:GetContactAction.cs

示例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"));
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Text,代码行数:13,代码来源:JsonObjectTests.cs

示例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 );
            }
开发者ID:SparkDevNetwork,项目名称:Rock,代码行数:15,代码来源:BlockTypeTests.cs


注:本文中的System.Collections.Generic.ToJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。