引用: Newtonsoft.Json.dll
// 引用: using Newtonsoft.Json; using Newtonsoft.Json.Converters;
// 定义 实体测试类 public class Customer { public string name { get; set; } public string code { get; set; } public Customer() // 貌似空构造函数必须 { } public Customer(string name, string code) { this.name = name; this.code = code; } }
List<Customer> cusList = new List<Customer>(); cusList.Add(new Customer("tom", "001")); cusList.Add(new Customer("Jack", "002")); cusList.Add(new Customer("Jerry", "003")); string jsonStr = JavaScriptConvert.SerializeObject(cusList); //序列化成 Json 格式 txt_RtnJson.Text = jsonStr; List<Customer> cusList2 = JavaScriptConvert.DeserializeObject<List<Customer>>(txt_fetchXml.Text); // 将 Json 字符串.反序列化成 实体类对象集