Newtonsoft.Json
Newtonsoft.Json 是一款 .NET 平台中开源的 JSON 序列化和反序列化类库,示例代码:public class Account{ public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public IList<string> Roles { get; set; }}Account account = new Account{ Email = "james@example.com", Active = true, CreatedDate = new DateTime(2013, 1, 20, 0, 0, 0, ateTimeKind.Utc), Roles = new List<string> { "User", "Admin" }};string json = JsonConvert.SerializeObject(account, Formatting.Indented);// {// "Email": "james@example.com",// "Active": true,// "CreatedDate": "2013-01-20T00:00:00Z",// "Roles": [// "User",// "Admin"// ]// }Console.WriteLine(json);
页:
[1]