I am getting a response back from a RESTful API in the form of a JSON object. Normally, I can parse this just fine when the keys are known. For instance, I create a User
class like this:
[DataContract]
public class User
{
[DataMember]
public string id { get; set; }
[DataMember]
public string name { get; set; }
[DataMember]
public string email { get; set; }
}
All I have to do is pull read the response into my JSON deserializer and tell it the output is a <User> and I'm good to go. This falls short when making other requests, such as sales data. The response I get back is something like this:
{
"2010-11-24": {
"country": null,
"iso": null,
"product": null,
"downloads": 39,
"net_downloads": 38,
"updates": 6,
"revenue": "19.02",
"returns": 1,
"gift_redemptions": 0,
"promos": 0
},
"2010-11-25": {
"country": null,
"iso": null,
"product": null,
"downloads": 63,
"net_downloads": 63,
"updates": 6,
"revenue": "37.00",
"returns": 0,
"gift_redemptions": 0,
"promos": 0
}
}
If I could model this class as a [DataContract]
then I'd be golden, but since the first key is a date, I can't hard code that.
Is there a JSON library out there that can take this kind of response and turn it into a strongly-typed C# class?
For the record, I'm using the JSONHelper used in this SO question.