Search code examples
.netjsonasp.net-mvc-3viewjsonserializer

How to deserialize a JSON string in .NET, when you don't have a type for it


Check this URL:

http://api.stackoverflow.com/1.1/users/811785/questions?sort=votes

It's a URL from StackOveflow's API. The returned JSON is really complex, and I'd like to convert it into an object, so that I can use it in my ASP.NET MVC's view.

The problem is that, JavaScriptSerializer object's Deserialize method, takes a Type parameter as its second parameter. But the returned JSON is so complex, I don't want to create a strongly-typed object for deserializing it.

What should I do?


Solution

  • in .NET 4.0, you can using dynamic

    More here

    http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2010/08/22/using-c-4.0-and-dynamic-to-parse-json.aspx

    And more here

    http://dynamicjson.codeplex.com/