c# - JSON.NET Case Insensitive Deserialization not working -


i need deserialize json object casing of json unknown/inconsistent. json.net supposed case insensitive not working me.

my class definition:

public class myrootnode {     public string action {get;set;}     public mydata data {get;set;} }  public class mydata {     public string name {get;set;} } 

the json receive has action & data in lowercase , has correct casing myrootnode.

i'm using deserialize:

myrootnode responseobject = jsonconvert.deserializeobject<myrootnode>(jsonstring); 

it returns initialised myrootnode action , data properties null.

any ideas?

edit: added json

{    "myrootnode":{       "action":"pact",       "mydata":{          "name":"jimmy"       }    } } 

you need add additional class:

public class myrootnodewrapper {     public myrootnode myrootnode {get;set;} } 

and use:

myrootnodewrapperresponseobject = jsonconvert.deserializeobject<myrootnodewrapper>(jsonstring); 

https://stackoverflow.com/a/45384366/34092 may worth read. same scenario.

also, change:

public mydata data {get;set;} 

to:

public mydata mydata {get;set;} 

as per advice @demo , @guy .


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -