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.