erikkallen
erikkallen

Reputation: 34421

deserializing generic dictionary using json.net

I have a class looking like this:

class MyClass {
    public int Id;
    public Dictionary<int, MyClass[]> ChildValues;
}

when I try to deserialize this class using Json.NET:

 MyClass x = return JsonConvert.DeserializeObject<MyClass>(s);

I receive the error Expected a JsonObjectContract or JsonDictionaryContract for type 'System.Collections.Generic.Dictionary`2[System.Int32,MyClass[]]', got 'Newtonsoft.Json.Serialization.JsonDictionaryContract'.

What does this error message mean and how can I resolve it?

Upvotes: 1

Views: 1423

Answers (2)

erikkallen
erikkallen

Reputation: 34421

I found it. The problem was that the Json from the client was an array and not a dictionary (which in turn was because the script file was cached by IE).

Upvotes: 1

user170442
user170442

Reputation:

Take a look at JSON you have in s variable first.

Upvotes: 2

Related Questions