當前位置: 首頁>>代碼示例>>C#>>正文


C# MemoryTraceWriter.ToString方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.Serialization.MemoryTraceWriter.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# MemoryTraceWriter.ToString方法的具體用法?C# MemoryTraceWriter.ToString怎麽用?C# MemoryTraceWriter.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.Serialization.MemoryTraceWriter的用法示例。


在下文中一共展示了MemoryTraceWriter.ToString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Example

        public void Example()
        {
            #region Usage
            string json = @"{
              'FullName': 'Dan Deleted',
              'Deleted': true,
              'DeletedDate': '2013-01-20T00:00:00'
            }";

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            Account account = JsonConvert.DeserializeObject<Account>(json, new JsonSerializerSettings
            {
                TraceWriter = traceWriter
            });

            Console.WriteLine(traceWriter.ToString());
            // 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
            // 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
            // 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
            // 2013-01-21T01:36:24.450 Verbose Deserialized JSON: 
            // {
            //   "FullName": "Dan Deleted",
            //   "Deleted": true,
            //   "DeletedDate": "2013-01-20T00:00:00"
            // }
            #endregion

            Assert.AreEqual(4, traceWriter.GetTraceMessages().Count());
        }
開發者ID:b-bot-110,項目名稱:Newtonsoft.Json,代碼行數:30,代碼來源:TraceWriter.cs

示例2: Serialize

        private string Serialize(Foo1 f)
        {
            //Code copied from JsonConvert.SerializeObject(), with addition of trace writing
            JsonSerializer jsonSerializer = JsonSerializer.CreateDefault();
            var traceWriter = new MemoryTraceWriter();
            jsonSerializer.TraceWriter = traceWriter;

            StringBuilder sb = new StringBuilder(256);
            StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture);
            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.None;
                jsonSerializer.Serialize(jsonWriter, f, typeof(Foo1));
            }

            Console.Out.WriteLine("Trace output:\n{0}", traceWriter.ToString());

            return sw.ToString();
        }
開發者ID:NiklasGillstrom,項目名稱:Newtonsoft.Json,代碼行數:19,代碼來源:ShouldSerializeTests.cs

示例3: WriteJRawInArray

        public void WriteJRawInArray()
        {
            ITraceWriter traceWriter = new MemoryTraceWriter();

            List<JRaw> raws = new List<JRaw>
            {
                new JRaw("$('#element')"),
                new JRaw("$('#element')"),
                new JRaw("$('#element')")
            };

            string json = JsonConvert.SerializeObject(raws, new JsonSerializerSettings
            {
                TraceWriter = traceWriter,
                Formatting = Formatting.Indented
            });

            StringAssert.AreEqual(@"[
  $('#element'),
  $('#element'),
  $('#element')
]", json);

            Assert.IsTrue(traceWriter.ToString().EndsWith(@"Verbose Serialized JSON: 
[
  $('#element'),
  $('#element'),
  $('#element')
]", StringComparison.Ordinal));
        }
開發者ID:ruisebastiao,項目名稱:Newtonsoft.Json,代碼行數:30,代碼來源:TraceWriterTests.cs

示例4: SerializationBasics

        public void SerializationBasics()
        {
            IList<string> roles = new List<string>
            {
                "User",
                "Admin"
            };

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            string j = JsonConvert.SerializeObject(roles, new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                TraceWriter = traceWriter
            });

            string trace = traceWriter.ToString();
            // Started serializing System.Collections.Generic.List`1[System.String].
            // Finished serializing System.Collections.Generic.List`1[System.String].
            // 2014-05-13T13:41:53.706 Verbose Serialized JSON: 
            // [
            //   "User",
            //   "Admin"
            // ]

            Console.WriteLine(trace);
        }
開發者ID:andersonb,項目名稱:Newtonsoft.Json,代碼行數:27,代碼來源:DemoTests.cs

示例5: WriteJRaw

        public void WriteJRaw()
        {
            ITraceWriter traceWriter = new MemoryTraceWriter();

            JRaw settings = new JRaw("$('#element')");
            string json = JsonConvert.SerializeObject(settings, new JsonSerializerSettings
            {
                TraceWriter = traceWriter
            });

            Assert.AreEqual("$('#element')", json);

            Assert.IsTrue(traceWriter.ToString().EndsWith("Verbose Serialized JSON: " + Environment.NewLine + "$('#element')", StringComparison.Ordinal));
        }
開發者ID:ruisebastiao,項目名稱:Newtonsoft.Json,代碼行數:14,代碼來源:TraceWriterTests.cs


注:本文中的Newtonsoft.Json.Serialization.MemoryTraceWriter.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。