序列化和反序列化示例

1.Model 类型

   public class SerializerBookModels    

   {       

       [DataMember]         public int ID { get; set; }

        [DataMember]         public string Name { get; set; }

        [DataMember]         public float Price { get; set; }

    }

   序列化内容:

    //序列化json            

    SerializerBookModels book = new SerializerBookModels() { ID = 101, Name = "C#程序设计", Price = 79.5f };

    string result = Serializer.ObjectToJson<SerializerBookModels>(book);

2.反序列化内容

   string oriStr = "{\"ID\":101,\"Name\":\"C#程序设计\",\"Price\":79.5}";
   SerializerBookModels outBook = Serializer.JsonToObject<SerializerBookModels>(oriStr);
   string ss = outBook.Name;

 

posted @ 2016-03-29 10:28  李寒星  阅读(168)  评论(0编辑  收藏  举报