c# - Deserialize a JSON to Class -


i trying desrialize string:

storage = "{\"1\":{\"1\":\"aaa\"},\"2\":{\"1\":\"bbb\"}}"; 

it works:

var localstorageobj1 = jsonconvert.deserializeobject<dictionary<datamodels.storageprimarykeys,                                                     dictionary<datamodels.storagesecondarykeys, string>>>(storage); 

but want class, like:

var localstorageobj = jsonconvert.deserializeobject<myclass>(storage); 

myclass is:

public class datamodels {     public enum storageprimarykeys     {         login = 1,         account = 2     };      public enum storagesecondarykeys     {         jobtitle = 1,         jobid = 2,         joblocation = 3,         renewdate = 4,         expirationdate = 5     }; }   public class myclass {     public dictionary<datamodels.storageprimarykeys, foriegndata> primarydictionary { get; set; } } public class foriegndata {     public dictionary<datamodels.storagesecondarykeys, string> foreigndictionary { get; set; } } 

unfortunately, got null when deserialized it.

any appreciated!

myclass not

dictionary<datamodels.storageprimarykeys, dictionary<datamodels.storagesecondarykeys, string>> 

myclass has

dictionary<datamodels.storageprimarykeys, dictionary<datamodels.storagesecondarykeys, string>> 

so should encapsulate json string properly:

{\"primarydictionary\" : {\"1\":{\"1\":\"aaa\"},\"2\":{\"1\":\"bbb\"}}}  

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -