C# .Net Deserialization $type Not Working -


i'm trying deserialize json using $type property. however, error stating "type specified in json not resolved. i'm not sure i'm doing wrong. appreciated.

my json

{ movies: [     {         $type:"rtmoviepagewithslides",         title:"reservoir dogs",         slides:[             {$type:"rtcharacterpage", title:"mr. orange",       img:""},             {$type:"rtcharacterpage", title:"mr. blonde",       img:""},             {$type:"rtcharacterpage", title:"mr. white",        img:""},             {$type:"rtcharacterpage", title:"mr. pink",         img:""},             {$type:"rtcharacterpage", title:"nice guy eddie",   img:""},         ]     }     {         $type:"rtmoviepagewithsubpages",         title:"jackie brown",         pages:[             {$type:"rtactorpage", title:"pam gier",             other_movies:[]},             {$type:"rtactorpage", title:"samuel l. jackson",    other_movies:[]},             {$type:"rtactorpage", title:"robert forester",      other_movies:[]}         ]     } ] } 

my classes

using system.collections; using system.collections.generic;  public class rtmoviedata {     public list<rtmoviepage> movies;     }  public class rtmoviepage {     public string title; }  public class rtmoviepagewithslides : rtmoviepage{     public list<rtmoviepage> slides = new list<rtslidepagedata>{}; }  public class rtmoviepagewithsubpages : rtmoviepage{     public list<rtmoviepage> pages = new list<rtpagedata>{}; }  public class rtcharacterpage : rtmoviepage {     public string img; }  public class rtactorpage : rtmoviepage {     public  list<string>other_movies; } 

deserialization code

var settings = new jsonserializersettings();     settings.typenamehandling = typenamehandling.auto;      rtmoviedata data = jsonconvert.deserializeobject<rtmoviedata>(jsonstring, settings); 

@programmer mentions post "deserialization of json using minijson" in unity c#" duplicate post. however, 2 posts not related @ all. other post describes user using different json deserializer , was having problem getting array deserialize. issue specific using $type property deserializer instantiate subclasses stated in title of post.

solution: in json needed add "assembly-csharp" value of $type property.

$type:"rtmoviepagewithslides, assembly-csharp" 

and

$type:"rtcharacterpage, assembly-csharp" 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -