简体   繁体   中英

How can i set "Serialize Default Values" to Yes in when deserializing?

I have the following , but the json string has some empty array that are no returned as empty. How can i set that options value to return regardless ?

vat det =   JsonConvert.DeserializeObject<RootObject>(json, "does option setting go here")  

There is something called a JsonSerializerSettings class where these kind of settings can be set. These settings can then be passed to with the DeserializeObject all after the json string. The setting you are looking for is called DefaultValueHandling this will be a enumerator in the settings with multiple settings. To see what is posible with these settings see their documentatie .

Your code will be looking something like this:

        var result = JsonConvert.DeserializeObject<RootObject>("json string", new JsonSerializerSettings
        {
            DefaultValueHandling = DefaultValueHandling.Ignore
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM