How do I deserialize the following JSON with Web API (JSON.Net)?:
{
"action": "edit",
"table": "MainView",
"id": "row_1377",
"_group_id": "999",
"data": {
"ROTATION": "1", // This name/val can change
"EQUIPMENT": [{
"id": "6"
},
{
"id": "8"
}],
"NOTES": ""
}
}
The values in data
represent columns and can change, so I can't make a set-in-stone object with e.g. a string named "NOTES" as in json.net deserialize string to nested class.
Notice EQUIPMENT
contains multiple values. When it was previously just a "string:string" like NOTES
, this JSON deserialized data
into a Dictionary<string, string>
, but now I need it to behave like its own dictionary. My last attempt was to deserialize into the following type:
public class EditorSubmissionJoined
{
public string _group_id { get; set; }
public string action { get; set; }
public string table { get; set; }
public string id { get; set; }
// "public" added below due to mistake noticed by Maggie Ying
public Dictionary<string, object> data { get; set; } // Trouble
}
I was hoping that the object
could contain anything in data
whether a KeyValuePair
(like NOTES
) or a dictionary (like EQUIPMENT
).
I've also tried Dictionary<string, ICollection<Object>>
, Object
, and even ICollection<Dictionary<string, Object>>
.
The problem is that my controller always gets EditorSubmissionJoined with nothing but null values:
public void Put(EditorSubmissionJoined ajaxSubmission) {
// ajaxSubmission has only NULL values
}