I'm creating a json object on the fly ( without Json.net ) via :
dynamic expando = new ExpandoObject();
expando.Age = 42;
expando.Name = "Royi";
expando.Childrens = new ExpandoObject();
expando.Childrens.First = "John";
Which looks like :
And so , I can query it like :
Console.WriteLine (expando.Name); //Royi
Ok , so let's serialize it :
var jsonString = new JavaScriptSerializer().Serialize(expando);
Console.WriteLine (jsonString);
Result :
[{"Key":"Age","Value":42},{"Key":"Name","Value":"Royi"},{"Key":"Childrens","Value":[{"Key":"First","Value":"John"}]}]
Notice how expando ( which is Idictionary of string,object) is keeping data
Question
Now I want the string to be deserialized back to :
I have tried :
var jsonDeserizlied = new JavaScriptSerializer().Deserialize<ExpandoObject>(jsonString);
But :
Type 'System.Dynamic.ExpandoObject' is not supported for deserialization of an array.
So , How can I get
[{"Key":"Age","Value":42},{"Key":"Name","Value":"Royi"},{"Key":"Childrens","Value":[{"Key":"First","Value":"John"}]}]
back to expando representation ?
nb
we don't use JSON.net.
update
I have managed to change object[]
to IList<IDictionary<string,object>>
:
var jsonDeserizlied = new JavaScriptSerializer().Deserialize<IList<IDictionary<string,object>>>(jsonString);
Which is now :
but again , I need to transform it to :