I'm trying to deserialize JSON to C# object using NewtonsoftJson.
My json looks like this:
{"something" : [ "key1" : "value1", "key2" : "value2"]}
But it's not a full json. So it should be kind of part of large object. I can't use this solution JSON array to C# Dictionary because I use
JsonConvert.DeserializeObject<MyObject>(json);
Does it possible to initialize object like this?
public class Something
{
[JsonProperty]
public Dictionary<string, string> MyDictionary;
}
But when I'm trying to do that I get exception:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,ConsoleApp4.TxPerfMeasurements]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.

{...}and not[...]. With the current example data there is no way you can get Json.Net to deserialize this, no matter what types you try to deserialize it into. Please ensure you have the right input example.