Problems related to the conversion of string to bool and int to bool in WebAPI Parameters
My colleague asked me a question today. I used postman to pass the json string to the interface. The value obtained by the interface is incorrect.
The following json data is displayed:
{
"Mark": "1"
}
The model member fields of the interface are defined as follows:
{Public bool Mark {set; get ;}}
Similar code. In this way, the value obtained by the webapi interface is false. If "true" is passed, the value obtained by the model is true. You can also try other examples,
If the passed value is not "true", the value obtained by the model is false..
Int-to-bool conversion is similar. The corresponding bool type field in the json parameter transmits a number not equal to 0 (including decimal and negative numbers) (test-0, at that time, when the brain was exhausted,-0 was also 0, so the ing value must be false), then the value of the corresponding bool type field in the model is true, otherwise it is false.
The above is a summary of the problems encountered in personal development. If you have any questions or are incorrect, please criticize and correct them.
QQ: 641591140