How to parse the Json data in windows phone 8

前端 未结 2 1402
情深已故
情深已故 2021-01-06 11:33

I am new to windows phone 8 development. I am working on application in which I need parse the Json. so I am not able to get the following data in windows phone 8.



        
相关标签:
2条回答
  • 2021-01-06 12:05
    var result= JObject.Parse(response)["response"]["ScoreDetail"];
                                        foreach (var item in result)
                                        {
    
    // Code to store the result
    }
    
    0 讨论(0)
  • 2021-01-06 12:06

    I propose you to build classes of your 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 the 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 you got 39.
            foreach (JObject detail in pair.Value as JArray)
            {
                string date = detail["test_date"].ToString();
                string score = detail["score"].ToString();
                string total_marks = detail["total_marks"].ToString();
            }
        }
    }
    

    Hope it helps !

    0 讨论(0)
提交回复
热议问题