发布:2015/5/31 15:30:00作者:管理员 来源:本站 浏览次数:1438
class Program { static void Main(string[] args) { //Product.GetAllSmartPhones(); List<Person> nums = new List<Person>(); nums.Add(new Person() { id=1, name="sara" }); nums.Add(new Person() { id=1, name="sylar" }); DataContractJsonSerializer json = new DataContractJsonSerializer(nums.GetType()); string szJson = ""; //序列化 using (MemoryStream stream = new MemoryStream()) { json.WriteObject(stream, nums); szJson = Encoding.UTF8.GetString(stream.ToArray()); } Console.WriteLine(szJson); Console.ReadLine(); } } [DataContract] class Person { [DataMember] public int id; [DataMember] public string name; } 注意类上面的那个特性
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4