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;