Question

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?

OTHER TIPS

With Json.NET you can do something like this

JObject o = JObject.Parse(json);

string name = (string)o["Name"];

You don't need an extra library like JSON.NET and just work with JavaScriptSerializer.

You may consider JavaScriptSerializer.DeserializeObject which will return an Object which is basically a Dictionary<string, object>.

You have to keep on casting to get the nested value.

See the deserialized object in your Quick Watch, then you will know what exactly you need to cast your returned Dictionary<>

Try System.Web.Script.JavascriptSerializer which is having many Deserialize overloaded methods, play with it, and you will surely get what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top