I have the following code:
var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent);
The input in responsecontent
is JSON, but it is not properly parsed into an object. How should I properly deserialize it?
I have the following code:
var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent);
The input in responsecontent
is JSON, but it is not properly parsed into an object. How should I properly deserialize it?
I am assuming you are not using Json.NET (Newtonsoft.Json NuGet package). If this the case, then you should try it.
It has the following features:
Look at the example below. In this example,
JsonConvert
class is used to convert an object to and from JSON. It has two static methods for this purpose. They areSerializeObject(Object obj)
andDeserializeObject<T>(String json)
:Try the following code:
Here are some options without using third party libraries:
See the link for more information about System.Web.Helpers.Json.
Update: Nowadays the easiest way to get the
Web.Helpers
is to use the NuGet package.If you don't care about earlier windows versions you can use the classes of the
Windows.Data.Json
namespace:System.Json works now...
Install nuget https://www.nuget.org/packages/System.Json
Sample:
The following from the msdn site should I think help provide some native functionality for what you are looking for. Please note it is specified for Windows 8. One such example from the site is listed below.
It utilizes the Windows.Data.JSON namespace.