Convert int for bool to json deserialization

I have a class that I use JavaScriptSerializer.Deserialize<class>

One of the properties I get from the user interface is int (0 or 1). Is there a way to change getter / setter to a property in C # so that it understands that it should return true or false based on the value? Or do I need another property that checks int prop? Thanks

+4
source share
1 answer

The best way is to create your own JavaScriptConverter , which you can use to process your object and convert between different data types. Override serialization / deserialization methods and analyze the format as you like.

Here's a link to the previous answer I wrote that implements JavaScriptConverter, showing you how you pass it to the JavaScriptSerializer object: fooobar.com/questions/147745 / ...

+3
source

Source: https://habr.com/ru/post/1394624/


All Articles