I'm working with an inconsistent Json that i want to deserialize to .Net class of mine. The problem is that sometime i have an Object and sometime it is an Array. What is the best way to do this? Converter? Below is a snippet of my Json Data
[
{
"@class": "odd",
"td": [
{
"@class": "user",
"@onmouseover": "userInfo('469');",
"@onmouseout": "userInfo(0);",
"@onmousemove": "moveSlotInfo();",
"#text": " AAA"
},
{
"@id": "day-469-2014-04-07",
"@style": "vertical-align: top;",
"table": {
"@class": "ss",
"@cellspacing": "1",
"tbody": {
"tr": {
"td": {
"@class": "as",
"@style": "color: #ffffff; background-color: #4040ff;",
"@onmouseover": "this.className=(document.week_vs_doctor.activityId.value==-1?'sd':'sp');slotInfo('177935',false);",
"@onmouseout": "this.className='as';slotInfo(0,false);",
"@onmousemove": "moveSlotInfo();",
"#text": "KAVAul"
}
}
}
}
}
]
},
{
"@class": "even",
"td": [
{
"@class": "user",
"@onmouseover": "userInfo('262');",
"@onmouseout": "userInfo(0);",
"@onmousemove": "moveSlotInfo();",
"#text": " BBB"
},
{
"@id": "day-262-2014-04-07",
"@style": "vertical-align: top;",
"table": {
"@class": "ss",
"@cellspacing": "1",
"tbody": {
"tr": [
{
"td": {
"@class": "as",
"@style": "color: #ffffff; background-color: #4040ff;",
"@onmouseover": "this.className=(document.week_vs_doctor.activityId.value==-1?'sd':'sp');slotInfo('174318',false);",
"@onmouseout": "this.className='as';slotInfo(0,false);",
"@onmousemove": "moveSlotInfo();",
"#text": "KAVA "
}
},
{
"td": {
"@class": "as",
"@style": "color: #000000; background-color: #ffc0c0;",
"@onmouseover": "this.className=(document.week_vs_doctor.activityId.value==-1?'sd':'sp');slotInfo('174338',false);",
"@onmouseout": "this.className='as';slotInfo(0,false);",
"@onmousemove": "moveSlotInfo();",
"#text": "Dagbak"
}
}
]
}
}
}
]
}
]
The problem is with the tr object either have Object or Array.
Below is my class snippet
public class Td2
{
[JsonProperty("@class")]
public string TdClass { get; set; }
[JsonProperty("@style")]
public string style { get; set; }
[JsonProperty("@onmouseover")]
public string onmouseover { get; set; }
[JsonProperty("@onmouseout")]
public string onmouseout { get; set; }
[JsonProperty("@onmousemove")]
public string onmousemove { get; set; }
[JsonProperty("#text")]
public string text { get; set; }
}
public class Tr2
{
public Td2 td { get; set; }
}
public class Tbody2
{
[JsonProperty]
[JsonConverter(typeof(ScheduleJsonConverter<Tr2>))]
public List<Tr2> tr { get; set; }
}
public class Table
{
[JsonProperty("@cellspacing")]
public string cellspacing { get; set; }
public Tbody2 tbody { get; set; }
[JsonProperty("@class")]
public string tClass { get; set; }
}