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


C# JsonSerializer.SerializeToString方法代码示例

本文整理汇总了C#中JsonSerializer.SerializeToString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.SerializeToString方法的具体用法?C# JsonSerializer.SerializeToString怎么用?C# JsonSerializer.SerializeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonSerializer的用法示例。


在下文中一共展示了JsonSerializer.SerializeToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_serialize_and_deserialize_text_email

        public void Can_serialize_and_deserialize_text_email()
        {
            var serializer = new JsonSerializer<EmailMessage>();
            var email = MessageFactory.EmailWithText(1).Single();
            var json = serializer.SerializeToString(email);
            Assert.IsNotNull(json);
            
            Console.WriteLine(json);

            var deserialized = serializer.DeserializeFromString(json);
            Assert.IsNotNull(deserialized);
        }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:12,代码来源:EmailSerializerTests.cs

示例2: Main

        static void Main(string[] args)
        {
            var violations = 0;
            const int count = 1000 * 1000;
            var json = new List<string>();
            var serializer = new JsonSerializer<T>();
            for (int i = 0; i < count; i++)
            {
                var t = new T
                {
                    X = Guid.NewGuid(),
                    Y = i % 2 == 0 ? 'C' : 'P',
                };
                json.Add(serializer.SerializeToString(t));
            }

            var tasks = new List<Task>();
            var tasksCount = args.Length > 0 ? int.Parse(args[0]) : 3;
            for (int jj = 0; jj < tasksCount; jj++)
            {
                int j = jj;
                tasks.Add(Task.Run(() => {
                    for (int i = 0; i < count; i++)
                    {
                        string s = json[i];
                        var t = serializer.DeserializeFromString(s);
                        if (t.Y != (i % 2 == 0 ? 'C' : 'P'))
                        {
                            violations++;
                            Console.WriteLine("Constraint violation index {0} thread {1} expected: {2} received: {3} json: {4}",
                                i, j, i % 2 == 0 ? 'C' : 'P', t.Y, s);
                        }
                    }
                }));
            }
            tasks.ForEach(task => task.Wait());

            Console.WriteLine($"There were {violations} viloations, running {tasksCount} Tasks");
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Text,代码行数:39,代码来源:Program.cs

示例3: test_rect_different_cultures

 public void test_rect_different_cultures(string culture)
 {
     var currentCulture = CultureInfo.GetCultureInfo(culture);
     Thread.CurrentThread.CurrentCulture = currentCulture;
     Thread.CurrentThread.CurrentUICulture = currentCulture;
     var s = new JsonSerializer<Rect>();
     var r = new Rect(23, 34, 1024, 768);
     var interim = s.SerializeToString(r);
     var r2 = s.DeserializeFromString(interim);
     Assert.AreEqual(r, r2);
 }
开发者ID:Jiannan,项目名称:ServiceStack.Text,代码行数:11,代码来源:StructTests.cs

示例4: PersonGenerator

 static PersonGenerator()
 {
     _names = File.ReadAllText("names.json").FromJson<Names>();
     var serializer = new JsonSerializer<Person>();
     _emptySize = serializer.SerializeToString(new Person()).Length;
 }
开发者ID:pvasek,项目名称:RavenVsMongo,代码行数:6,代码来源:PersonGenerator.cs

示例5: CacheCurrentTask

		protected void CacheCurrentTask()
		{
			if (LocalCachingEnabled)
			{
				var serializer = new JsonSerializer<TaskMessage>();
				File.WriteAllText(Settings.Default.LocalCache, serializer.SerializeToString(CurrentTask));
			}
		}
开发者ID:e-travel,项目名称:RedisQueue.Net,代码行数:8,代码来源:QueueClient.cs


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