Problems related to the conversion of string to bool and int to bool in WebAPI Parameters

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.