c# - How to parse the Json data in windows phone 8 -


i new windows phone 8 development. working on application in need parse json. not able following data in windows phone 8.

 {    "response":{       "errorflag":0,       "score detail":{          "39":[             {                "test_date":"2013-06-28",                "total_marks":"50",                "score":"14"             },             {                "test_date":"2013-08-08",                "total_marks":"20",                "score":"20"             }          ],          "40":[             {                "test_date":"2013-08-08",                "total_marks":"20",                "score":"20"             },             {                "test_date":"2013-08-08",                "total_marks":"30",                "score":"20"             },             {                "test_date":"2013-08-08",                "total_marks":"30",                "score":"20"             }          ],          "50":[             {                "test_date":"2013-08-08",                "total_marks":"30",                "score":"20"             }          ]       }    } } 

i trying parse data in following way

namespace testscore { public partial class mainpage : phoneapplicationpage { public mainpage()     {         initializecomponent();         loaded += new routedeventhandler(mainpage_loaded);     }  void mainpage_loaded(object sender, routedeventargs e)     {         webclient webclient1 = new webclient();         webclient1.downloadstringcompleted += new downloadstringcompletedeventhandler(webclient1_downloadstringcompleted);         webclient1.downloadstringasync(new uri("some link"));     }  public void webclient1_downloadstringcompleted(object sender, downloadstringcompletedeventargs e)     {         var rootobject = jsonconvert.deserializeobject<rootobject>(e.result);         messagebox.show(e.result.tostring());         foreach (var res in rootobject.response.scoredetail)         {             string rs = res.key;             messagebox.show(rs.tostring());              ......         }                                               }  public class rootobject     {         public response response { get; set; }     }      public class response     {         public int errorflag { get; set; }         [jsonproperty("score detail")]         public jobject scoredetail { get; set; }                } 

here getting key value (here 39) not able values of score, testdate , marks. please me in parsing these details.

thanks in advance.

i propose build classes of json :

public class rootobject {     public response response { get; set; } }  public class response {     public int errorflag { get; set; }     [jsonproperty("score detail")]     public jobject scoredetail { get; set; } } 

you can use them on downloadstringcompleted event :

public void webclient1_downloadstringcompleted(object sender, downloadstringcompletedeventargs e) {     rootobject root = jsonconvert.deserializeobject<rootobject>(e.result);     jobject obj = root.response.scoredetail;     foreach (keyvaluepair<string, jtoken> pair in obj)     {            string key = pair.key; // here got 39.         foreach (jobject detail in pair.value jarray)         {             string date = detail["test_date"].tostring();             string score = detail["score"].tostring();             string total_marks = detail["total_marks"].tostring();         }     } } 

hope helps !


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -