1.将类转换成Json
定义实体类
public class Person
{
public string Name { set; get; }
public int Age { set; get; }
}
json转换
//转成json
string json = JsonConvert.SerializeObject(new Person() { Name = "风铃", Age = 18 });
Console.WriteLine(json);
//json转实体
Person p = (Person) JsonConvert.DeserializeObject(json,typeof(Person));
Console.WriteLine(p.Name);