This project is read-only.

JsonValue - create enums from string

Dec 12, 2011 at 8:42 PM


I am parsing some Json that I retrieve using HttpClient, and turning it into a strongly-typed object using JsonValue.ReadAsType<T>.

The type I am creating has some properties which I would like to be Enums, but the Json I am receiving contains the names of the enum value, rather than the int value.

When I try to create the object using this, I get a parsing error but if I make the property a string, then it's fine.

Is there a way to support parsing Json using JsonValue so that the string values are converted to the right enum value?

Hope that makes sense!