标签:style blog class c code java
1 对象
public class Person { public string Name { get; set; } public int Age { get; set; } public DateTime Birth { get; set; } public string BirthDay { get; set; } }
2 封装成json格式
Person person = new Person(); person.Name = "张小晓"; person.Age = 10; person.Birth = new DateTime(1990, 11, 22); person.BirthDay = person.Birth.ToString("yyyy-MM-dd"); JavaScriptSerializer js = new JavaScriptSerializer(); string result = js.Serialize(person); Console.WriteLine(result); Console.Read();
3 结果
注意有一个DateTime的转换,转换后为红字部分,这个需要特殊处理一下。比如用字符串,如BirthDay。
标签:style blog class c code java
原文地址:http://www.cnblogs.com/tianxue/p/3738339.html