1, add Reference Newtonsoft.Json.dll (attachment: Https://files.cnblogs.com/files/chen-yuan/Newtonsoft.zip); 2, reference:
using Newtonsoft.Json.Linq;
3, the specific code:
stringStudents ="{\ "grade\": \ "6\", \ "class\": \ "1\", \ "Students\": [{\ "id\": \ "1\", \ "name\": \ "lily\", \ "sex\": \ "female \"},{\ "id\": \ "2 \ ", \" name\ ": \" Jack\ ", \" sex\ ": \" male d\ "},{\" id\ ": \" 3\ ", \" name\ ": \" lucy\ ", \" sex\ ": \" woman \ "}]}"; Jobject Studentsjson=Jobject.parse (students);//GradestringGrade = studentsjson["Grade"]. ToString ();//get the name of a second studentstringname1 = studentsjson["Students"][1]["name"]. ToString ();//Orname1 = studentsjson["Students"]. AsEnumerable (). ElementAt (1)["name"]. ToString ();//Traverse Student InformationvarStudentslist = studentsjson["Students"]. AsEnumerable ();foreach(varIteminchstudentslist) { stringA = item["name"]. ToString ();}//get student Jack's information and gendervarJack = studentsjson["Students"]. AsEnumerable (). Where (t = t.value<string> ("name") =="Jack");stringJack_sex = Jack.firstordefault () ["Sex"]. ToString ();//get a collection of girls ' informationvarGirls = studentsjson["Students"]. AsEnumerable (). Where (t = t.value<string> ("Sex") =="A woman?");
Various JSON values in C #