views:

538

answers:

2

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?

+2  A: 

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

Rafal Ziolkowski
+1  A: 

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).

erikkallen