1.Nuget 下载 Newtonsoft.Json
2.需要解析的字符串数据 message
{ "code": 200, "msg": "SUCCESS", "data": { "id": "12345678", "name": "张三", "sex": "男", "result": { "access_token": "49d58eacd7811e463429a1ae10b42173", "user_info": [{ "school": "社会大学", "major": "软件开发", "education": "本科", "score": 97 }, { "school": "湖南大学", "major": "软件工程", "education": "研究生", "score": 100 }] } } }
3.获取数据
JObject result = JObject.Parse(message);//假设result为数据结构 UserInfo userinfo = new UserInfo(); userinfo.id = result["data"].Value<string>("id");//id userinfo.name = result["data"].Value<string>("name"); //name userinfo.sex = result["data"].Value<string>("sex"); //sex userinfo.access_token= result["data"]["result"]["access_token"].ToString();//access_token JArray res = result["data"]["result"].Value<JArray>("user_info"); JObject obj = JObject.Parse(res[0].ToString());//只获取数据结构中第一个userinfo里的数据信息 userinfo.school = obj.Value<string>("school"); //schoool userinfo.major = obj.Value<string>("major");//major userinfo.education = obj.Value<string>("education");//education userinfo.score= obj.Value<string>("score");//score