0

Here is my json object: {"result":"ok","dataType":"2","Data":[["5","1"],["6","2"],["7","3"],["8","4"],["9","5"],["10","6"],["41","7"]]}

I want to deserialize this to a custom c# class that looks like this:

[Serializable]
public class DataRow
{
    public string Result { get; set; }
    public string Action { get; set; }
    public string DataType { get; set; }
    public IEnumerable<KeyValuePair<string, string>> Data { get; set; }
}

How can I do this using the .Net JavaScriptSerializer?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Kulvis
  • 655
  • 11
  • 33
  • does new JavaScriptSerializer().Deserialize(yourJsonObjectString) not work? –  Jan 26 '12 at 06:45
  • no. fails on the datatype KeyValuePair. – Kulvis Jan 27 '12 at 22:00
  • Can you change that type to Dictionary? I remember having issues with trying to serialize dictionary-like collections myself, and I think only string-string dictionary can be automatically [de]serialized using JavaScriptSerializer; your type in that place is similar; you should be able to work with dic whereever you're using it (I mean, if deserialization works that way). –  Jan 27 '12 at 22:30
  • Also see this: http://stackoverflow.com/questions/6416950/serializing-dictionaries-with-javascriptserializer; it may be that this Json.NET lib can do more than JavaScriptSerializer. –  Jan 27 '12 at 22:34

1 Answers1

0

Changed the datatype of Data to string[][]. Works like a charm!

Kulvis
  • 655
  • 11
  • 33