I have a json as below :
"[{"a":"b","c":"d"},{"a":"e","c":"f"},{"a":"g","c":"h"}]"
now I want to deserilize this into a list of objects of anonymous type “foo”
var foo=new { a=string.empty , c=string.empty };
the code is :
ServiceStackJsonSerializer Jserializer = new ServiceStackJsonSerializer();
dynamic foos = Jserializer.Deserialize<List<foo.GetType()>>(jsonString);
but not working .
update :
replacing ServiceStack with JavascriptSerializer and passing dictionary[] solved the problem without need to anonymous Type
JavaScriptSerializer jSerializer = new JavaScriptSerializer();
var Foos = jSerializer.Deserialize<Dictionary<string, object>[]>(jsonString);
I don’t know what the
Jserializerclass is, but I do know of theJavaScriptSerializerclass. Unfortunately, it doesn’t support deserialization into anonymous types. You’ll have to create a concrete type like this:Using the following code worked for me:
the variable
fooswill contain an array ofFooinstances.