序列化(SerializeObject)与反序列化(DeserializeObject)。
打开Nuget安装Newtonsoft.Json:
class Bl { public void SerialAndDeser() { List<string> a = new List<string>() { "rt","qu","br","ld","ej"}; string s = JsonConvert.SerializeObject(a); Console.WriteLine(s); } }
Source Code
List<string> a经过序列化之后,返回的结果:
接来来,我们把经过序列化后的s,再反序列化回List<string>集合:
List<string> b = JsonConvert.DeserializeObject<List<string>>(s); b.ForEach(delegate (string t) { Console.WriteLine(t); });
Source Code
控制台测试并输出结果: