I am having a problem binding an array of key value pair objects in MVC5. This is the JSON:
{
"expiration": "2013-12-03T04:30:41.206Z",
"conditions": [
{
"acl": "private"
},
{
"bucket": "ryvus.upload.test"
},
{
"Content-Type": "application/vnd.ms-excel"
},
{
"success_action_status": "200"
},
{
"key": "fc42ae8a-1f6e-4955-a669-8272ad650cb9.csv"
},
{
"x-amz-meta-qqfilename": "simpleupload.csv"
}
]
}
If I attempt to bind conditions to a Dictionary<string, string> like this:
// View Model
public class ResponseVM
{
public DateTime Expiration { get; set; }
public Dictionary<string, string> Conditions { get; set; }
}
// Controller Action
public ActionResult MyHandler(ResponseVM s3Response)
{
//do something
return JSON(null);
}
I get a 6 entries with keys of "0","1","2","3","4","5" and null values. I seem so close but I've tried a bunch of different types without success, the Dictionary<string, string> was the best I could get.
Am I missing something completely obvious here?
conditionsJSON doesn't fit the expected schema for the dictionary so you either need to modify the JSON schema or customize the deserializationconditionsdata type instead? Should it really be a dictionary?