Simply remember that JSON parsing is simple and practical:
Usage Scenario: JSON data that is uploaded to the client in the background, similar to:
string jsonobject="{' Name ': ' Jack ', ' age ': +}"; string " [{' Name ': ' Jhon ', ' age ': ' 23},{' name ': ' Jack ', ' age ':] " ;
A client can define a class in which the properties in the class correspond to the corresponding fields in the data
class student{ publicstringgetset;} Public int Get Set ; }}
Add Newtonsoft.json references through NuGet packages and add using Newtonsoft.Json.Linq; namespaces
Create the Jtoken object and parse the above string:
Jtoken Jtoken = jtoken.parse (jsonobject); Jtoken jtoken2=jtoken.parse (Jsonarray);
The data can then be converted to the appropriate object:
if(Jtoken1 isjobject) {Student s=jtoken. Toobject<student>(); Console.WriteLine (S.name); Console.WriteLine (S.age); }if(Jtoken2 isJarray) {List<Student> students = Jtoken2. Toobject<list<student>>(); foreach(varStudentinchstudents) {Console.WriteLine (string. Format ("Name:{0}\tage:{1}", student. Name, student. Age)); }}
Simply introduce a way to parse the data:)
Spents: 10min
Simple use of JSON parsing data