JSON Deserialize with empty field c# -
i'm testing api calls in c# , getting following json response:
{ "message": "the request invalid. model validation failed.", "validationerrors": { "": { "reasons": [ "a customer must added order before can placed." ] } } }
i want map response class json deserializer , have no control on how response formed. how handle empty field in validationerrors can still access reasons list in object?
note: when ran through json2csharp gave not useful mapping field within validationerrors class.
public __invalid_type__ __invalid_name__ {get;set;}
deserialize dictionary<string, validationerror>
:
public class validationerror { public list<string> reasons { get; set; } } public class rootobject { public string message { get; set; } public dictionary<string, validationerror> validationerrors { get; set; } }
this work out-of-the-box javascriptserializer , json.net. if using datacontractjsonserializer
(tagged datacontractjsonserialize) need set datacontractjsonserializer.usesimpledictionaryformat = true
(.net 4.5 , above only).
Comments
Post a Comment