How to deserialize json data in windows phone?

后端 未结 2 916
醉话见心
醉话见心 2021-01-29 00:35

Initially my json was in the format,

\"code\": 0,
\"message\": \"success\",
\"students\": [
    {
        \"id\": \"257633000000070001\",
        \"name\": \"hje         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 01:34

    If you using Newtonsoft.Json, try to use that classes:

    public class StudentDetails
    {
        public string id { get; set; }
        public string name { get; set; }
        public int percentage { get; set; }
        public string type { get; set; }
    }
    
    public class Student
    {
        public int code { get; set; }
        public string message { get; set; }
        public List students { get; set; }
    }
    

    After that, you can use that class to Deserialize responses using following way:

    var parsedResponse = JsonConvert.DeserializeObject(data);
    

    P.S. Of course, do not forget about [DataContract] and [DataMember] attributes

提交回复
热议问题