Is there a way to deserialize JSON content into a C# dynamic type? It would be nice to skip creating a bunch of classes in order to use the DataContractJsonSerializer.
Is there a way to deserialize JSON content into a C# dynamic type? It
Share
If you are happy to have a dependency upon the
System.Web.Helpersassembly, then you can use theJsonclass:It is included with the MVC framework as an additional download to the .NET 4 framework. Be sure to give Vlad an upvote if that’s helpful! However if you cannot assume the client environment includes this DLL, then read on.
An alternative deserialisation approach is suggested here. I modified the code slightly to fix a bug and suit my coding style. All you need is this code and a reference to
System.Web.Extensionsfrom your project:You can use it like this:
So, given a JSON string:
The following code will work at runtime: