I have a single level json that I want to deserialize into a Dictionary<string,object>
using Json.Net.
The dictionary's value can be a primitive, string or a (primitive\string) array.
The deserialization knows how to handle primitives and strings, but when it gets to an array of primitives it deserializes it into a JArray
(instead of a primitive array).
Here's a small code example of what I mean:
string jsonStr = @"{""obj"": 7, ""arr"": ['1','2','3']}";
Dictionary<string, object> dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonStr);
dict["obj"].GetType(); // long
dict["arr"].GetType(); // JArray. I would like this to be string[].
I'm looking for a way I can interfere in the deserialization process and create a primitive array instead of getting stuck with a JArray
.
I've tried doing it with the JsonSerializerSettings
, but couldn't nail the spot.