I am dynamically deserializing Json strings and I want to have them convert into their appropriate types upon deserializing, but since it's dynamic I don't necessarily know what they will become. For example I might have a Json that looks like this:
string serializedJsonString = {
"stringValue": "someString",
"dateTimeObject": "2016-12-08"
};
I want this Json to be deserialized into their key-value pairs, but their values stored as their appropriate object types, in the example above as String
and DateTime
.
I've tried some of the following like:
IDictionary<string, object> blah = new JavaScriptSerializer().Deserialize<IDictionary<string, object>>(serializedJsonString);
And:
dynamic blah = Json.Decode(serializedJsonString);
But it always just converts the "dateTimeObject" to a string. I've been told deserializing the Json can do this conversion, but I can't figure out how. What am I doing wrong?