0

I have this string:

string json = "[[{"Key":"COL1","Value":"8404"},{"Key":"LIN1","Value":"972"},{"Key":"CAT","Value":"C"}],[{"Key":"COL1","Value":"8406"},{"Key":"LIN1","Value":"971"},{"Key":"CAT","Value":"A"}]]";

I have defined this type:

public class Table : List<Dictionary<string, string>> { }

How can I deserialize the string into the Table class?

So far I tried this:

JavaScriptSerializer ser = new JavaScriptSerializer(); 
var values = ser.Deserialize<Table>(json);

But I get a length 0 variable

Naty Bizz
  • 2,262
  • 6
  • 33
  • 52
  • 1
    Possible duplicate of [How can I deserialize JSON to a simple Dictionary in ASP.NET?](http://stackoverflow.com/questions/1207731/how-can-i-deserialize-json-to-a-simple-dictionarystring-string-in-asp-net) – zerkms May 11 '17 at 22:08
  • One thing to note about the dupe: the `{"Key":"COL1", "Value":"8404"}` will be deserialized as a `Dictionary` with two entries (the first has a key of "Key" and a value of "COL1"). So, your specific JSON is actually representing an `List>>`. – Heretic Monkey May 11 '17 at 22:12
  • @zerkms the thing is how to deserialize into a derived/inherited class – Naty Bizz May 11 '17 at 22:13
  • If you are willing to switch to [tag:json.net], this becomes a duplicate of [Newtonsoft Json Deserialize Dictionary as Key/Value list from DataContractJsonSerializer](http://stackoverflow.com/a/28633769/3744182). – dbc May 11 '17 at 22:32

0 Answers0