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?
cdeserializationjsonjson.netparsing
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?
Best Answer
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:
JsonIgnore
andJsonProperty
can be added to a class to customize how a class is serializedLook 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)
: