I\'ve seen a lot of examples that seem to indicate that what I\'m doing should work, but for whatever reason, it doesn\'t. I\'m trying to deserialize a collection of objects
Obviously a little late to the part for the OP :) but I hit similar today and used the following to solve it:
//var json = "[{'firstName':'John', 'lastName':'Doe'},{'firstName':'Anna', 'lastName':'Smith'},{'firstName':'Peter','lastName': 'Jones'} ]";
//var json = "{ 'glossary': { 'title': 'example glossary','GlossDiv': { 'title': 'S','GlossList': { 'GlossEntry': { 'ID': 'SGML','SortAs': 'SGML','GlossTerm': 'Standard Generalized Markup Language','Acronym': 'SGML','Abbrev': 'ISO 8879:1986','GlossDef': { 'para': 'A meta-markup language, used to create markup languages such as DocBook.','GlossSeeAlso': ['GML', 'XML'] },'GlossSee': 'markup' } } } } }";
var json = "{ 'A': 'A0' , 'B' : { 'B2' : 'B2 - Val', 'B3' : [{'B30' : 'B30 - Val1' ,'B31' : 'B31 - Val1'}]}, 'C': ['C0', 'C1']}";
var jss = new JavaScriptSerializer();
try
{
// Deal with an Object root
var dict = jss.Deserialize>(json);
//
}
catch (InvalidOperationException ioX)
{
// Deal with an Array Root
var dictionaries = jss.Deserialize[]>(json);
foreach (var dict in dictionaries)
{
//
}
}