JSON sample one:
String jsontext=
{Code": 0,"Message":"Success","Data":{"Boardprovincename":"Shanghai","Boardcityname":"Shanghai","Boarddetailaddress":"No. 449, Lane 8th, Nujiang North Road, Putuo District C5","Couriername":"15601804660","Couriermobile":"15601804660","Cargono": The"Boardno": 3,"Boxno": 2,"Doorno": 3,"Expressno":"333333","Cargopassword": null,"Size": 3,"Status": 2,"Storetime":"\/date (1406772770183)\/","Extractiontime":"\/date (1415185496877)\/","Customermobile":"15601804660","Courierpid":"321323198902082117"}}}
Jobject Jo = Jobject.parse (jsontext); string strcode= jo["Code"]. ToString ();//code:0
String Ddaf = Getjsonvalue (Jo. Children (), "boarddetailaddress");//boarddetailaddress: No. 449 Lane 8th, Nujiang North Road, Putuo District C5
=====================================================================
without = = "["]
String jsondata = "{\" name\ ": \" lily\ ", \" age\ ": 23,\" addr\ ": {\" city\ ": \" guangzhou\ ", \" province\ ": \" guangdong\ "}}" ; Jobject jsonobj = jobject.parse (jsondata); String strname = jsonobj["name"]. ToString (); String strprovince = Getjsonvalue (Jsonobj.children (), "province");
=====================================================================
Class:
Public static string Getjsonvalue (Jenumerable<jtoken> Jtoken, string key) { IEnumerator Enumerator = Jtoken.getenumerator (); while (enumerator. MoveNext ()) { Jtoken JC = (Jtoken) Enumerator. Current; If (JC is Jobject | | ((Jproperty) JC). Value is Jobject) { return Getjsonvalue (JC. Children (), key); } else { if ((Jproperty) JC). Name = = key) { return (Jproperty) JC). Value.tostring (); }}} return null; }
=================================================================================
with = = "["]
stringJsontext ="{' name ': ' Test ', ' phone ': ' 18888888888 ', ' image ': [{' Name ': ' Img1 ', ' data ': ' data1 '},{' name ': ' Img2 ', ' data ': ' Data2 ' },{' name ': ' Img3 ', ' data ': ' Data3 '}]}"; stringJsonText1 ="{' name ': ' Test ', ' phone ': ' 18888888888 ', ' image ': [{' Name ': ' Img1 ', ' data ': ' Data1 '}]}"; Jobject Jo=(Jobject) jsonconvert.deserializeobject (Jsontext); stringZone = jo["name"]. ToString (); stringZone_en = jo["Phone"]. ToString (); Jarray Jar= Jarray.parse (jo["Image"]. ToString ()); stringc =Zone; stringD =zone_en; for(vari =0; I < jar. Count; i++) {Jobject J=Jobject.parse (Jar[i]. ToString ()); stringA = j["name"]. ToString (); stringb = j["Data"]. ToString (); }
Multilayer nesting
String jsonData1 = "{\" addr\ ": [{\" city\ ": \" guangzhou\ ", \" province\ ": \" guangdong\ "},{\" city\ ": \" guiyang\ ", \" Province\ ": \" Guizhou\ "}]}"; Jobject jsonObj1 = Jobject.parse (jsonData1); Jarray jar1 = Jarray.parse (jsonobj1["addr"]. ToString ()); Jobject j0 = Jobject.parse (jar1[0]. ToString ()); Jobject J1 = Jobject.parse (jar1[1]. ToString ()); String city1 = j0["City"]. ToString (); Guangzhou String city2 = j0["City"]. ToString (); Guiyang
The above pro-test available
C#json parsing