How to Customize Deserialization of a JSON enum in .NET? How to Customize Deserialization of a JSON enum in .NET? json json

How to Customize Deserialization of a JSON enum in .NET?


This behavior is by design. Here's a quote from the Enumerations and JSON paragraph on MSDN:

Enumeration member values are treated as numbers in JSON, which is different from how they are treated in data contracts, where they are included as member names.

Moreover the DataContractJsonSerializer will automatically serialize all enumerations, so the EnumMemberAttribute is actually ignored.

For a workaround, take a look at this answer on SO.


This is work :

var ret = new JavaScriptSerializer().Deserialize<tblGridProjects>(retApi.Item2);

But you can't use datamembers attributes, so can't rename properties.You must set the name of the property like Json sended.