/// <summary>
/// 先定義一個Person以供使用
/// </summary>
internal class Person
{
public string Name { set; get; }
public int Age { set; get; }
}
internal class Program
{
private static void Main(string[] args)
{
List<Person> list = new List<Person>();
list.Add(new Person { Name = "Mars", Age = 20 });
list.Add(new Person { Name = "Mary", Age = 25 });
string json = JsonConvert.SerializeObject(list);
Console.WriteLine("====== json ======");
Console.WriteLine(json);
dynamic[] data = JsonConvert.DeserializeObject<JObject[]>(json);
Console.WriteLine("====== data ======");
foreach (var item in data)
Console.WriteLine($@"Name: {item.Name} ,Age: {item.Age}");
Console.ReadKey();
}
}
結果
留言列表