您的位置:首页 > Web前端 > JavaScript

JSON使用TraceWriter反序列化获取调试日志

2015-12-11 14:26 513 查看
1.先创建一个Account对象,并添加属性.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JSONDemo
{
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreateDate { get; set; }
}
}


2.从JSON字符串中反序列化,使用MemoryTraceWriter对象来跟踪调试日志.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GongHuiNewtonsoft.Json;
using GongHuiNewtonsoft.Json.Serialization;

namespace JSONDemo
{
class Program
{
static void Main(string[] args)
{
string json = @"{
'Email':'359194966@qq.com',
'Active':false,
'CreateDate':'2015-12-11 14:17:33',
'Name':'GongHui'
}";

MemoryTraceWriter traceWriter = new MemoryTraceWriter();

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


3.运行的结果



JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: