//当存在一个json格式的字符串需要呗反序列化,但又不知道它对应的类型,此时可以使用匿名序列化。
//声明一个匿名对象,并初始化
var definition = new { Name = "" };
//使用匿名序列化函数
string json1 = @"{'Name':'James'}";
var customer1 = JsonConvert.DeserializeAnonymousType(json1, definition);
Console.WriteLine(customer1.Name);
// James
string json2 = @"{'Name':'Mike'}";
var customer2 = JsonConvert.DeserializeAnonymousType(json2, definition);
Console.WriteLine(customer2.Name);
// Mike
JSON.NET学习(6)--JSON匿名反序列化
最新推荐文章于 2023-07-23 17:54:09 发布