1.下载 Newtonsoft.Json
右键引用,选择 管理NuGet程序包,选择浏览,输入log4net,然后点击下载
2.json数据的组装与解析
public class Class { public int name { set; get; } public List<Student> students { set; get; } } public class Student { public int grade { set; get; } public int age { set; get; } public string name { set; get; } } //组装好类 Class Class1 = new Class(); //组装成json字符串: string strJson = JsonConvert.SerializeObject(Class1) //解析成类 Class Class2 = JsonConvert.DeserializeObject<Class>(strJson); //如果是http接口的解析,为防止服务器私增加Json字段,导致解析失败,最好按一下方式处理json JObject jObject = JsonConvert.DeserializeObject<JObject>(strJson); Class Class3 = new Class(); Class3.name= jObject ["name"].ToString().Trim();