Json.NET: Deserilization with list of objects

Sep 23, 2011 at 3:39 AM

I have also posted the question in stackoverflow

I am processing JSON responses(displayed below.) from a service on my Windows Phone 7 client. I am using Json.NET to Deserialize into an object, which contains List of products. But after I deserialize, when I looked into my serviceresponse object, I can see a list of products with count 2. But when I expand the product object, the fields under product (Name, ExpiryDate... etc ) are all null.
I guess my problem is with the way I have defined my serviceresponse class. Can someone help me to resolve the issue and get the correct output.
My deserilization code:

serviceresponse deserializedProduct = JsonConvert.DeserializeObject<serviceresponse>(json);


My Json response String:

{ "serviceresponse" : 

{ "company" : "ford", "success" : "Yes", "products" : [
  {"product" : 

      {
        "Name": "Product 1",
        "ExpiryDate": "\/Date(978048000000)\/",
        "Price": "99.95",
        "Sizes": "1"
      }
  },
  {"product" : 
      {
        "Name": "Product 2",
        "ExpiryDate": "\/Date(1248998400000)\/",
        "Price": "12.50",
        "Sizes": "1"
      }
  }
], "callbackformore" : "No", "message" : "1" 

    } 

}


My serviceresponse class:

[DataContract]
        public class serviceresponse
        {
        [DataMember]
        public String company;
        [DataMember]
        public String success;
        [DataMember]
        public List<product> products;
        [DataMember]
        public String callbackformore;
        [DataMember]
        public String message;

        }
    [DataContract]
        public class product
        {
        [DataMember]
        public String Name;
        [DataMember]
        public String ExpiryDate;
        [DataMember]
        public String Price;
        [DataMember]
        public String Sizes;
        }