Can I control what subtype to use when deserializing a JSON string?

If you use the System.Web.Script.Serialization. JavaScriptSerializer you can use the overload in the constructor to add your own class resolver: JavaScriptSerializer myserializer = new JavaScriptSerializer(new FacebookResolver()) An example how to implement this can be found here on SO: stackoverflow.com/questions/1027107/java... But you should replace the type": "video part to type": "video since this is the convention for the class Here is an example: public class FacebookResolver : SimpleTypeResolver { public FacebookResolver() { } public override Type ResolveType(string id) { if(id == "video") return typeof(Video); else if (id == "status") return typeof(Status) else return base. ResolveType(id); } }.

If you use the System.Web.Script.Serialization. JavaScriptSerializer you can use the overload in the constructor to add your own class resolver: JavaScriptSerializer myserializer = new JavaScriptSerializer(new FacebookResolver()); An example how to implement this can be found here on SO: stackoverflow.com/questions/1027107/java... But you should replace the "type": "video" part to "__type": "video" since this is the convention for the class. Here is an example: public class FacebookResolver : SimpleTypeResolver { public FacebookResolver() { } public override Type ResolveType(string id) { if(id == "video") return typeof(Video); else if (id == "status") return typeof(Status) else return base.

ResolveType(id); } }.

Interesting! I've made some changes and that FacebookResolver is firing. But I can't see my public List Results { get; set; } filled; Am I missing something?

– Rubens Farias Jul 25 '10 at 16:27 Just found another hint: when I use JavaScriptSerializer. DeserializeObject, I can see all children objects serialized, but inside a data property. Seems something is missing mapping DataMember(Name="data") attribute to that List Results property – Rubens Farias Jul 25 '10 at 17:08 Seems that __type property MUST be first one in JSON string; I tried to build a regex to order that attributes, but it's very hard to do.

Bottom line: I gave up trying to specialize that JSON objects and used a denormalized version. – Rubens Farias Aug 2 '10 at 9:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions