How to obtain and determine boolean values in json

Source: Internet
Author: User

How to obtain and determine boolean values in json

In fact, I clearly know that the returned data is of the boolean type,

It is only used directly when making judgments.

If([ResponseObjectobjectForKey: @ "success"]) It makes no sense to judge because it is true. In other words, it is not empty,

Of course it's not empty. It's a big deal to return a false value, but that is also worth it. so, I tried to change the data type for receiving,

When I use NSString * to receive the message,

This error occurs.

[_ NSCFBoolean is1_tostring:]: unrecognized selector sent to instance

OMG, okay. He is not of the String type, he is a boolean,

Then try [[responseObject objectForKey: @ "success"] boolValue];

Don't ask why I don't receive it directly with bool, because there is a fucking warning.

Sorry, I'm a little excited.

Now, let's summarize:

It is estimated that all numbers of the default id type received by iOS are of the NSNumber type, so here we need to set the value,

Oh, yes. If it is post, all the data is indeed NSNumber. In this case, the data received and sent in json is indeed in the NSNumber class.

That's all.



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.