开发者

NSMutableData to Int

开发者 https://www.devze.com 2023-01-18 19:08 出处:网络
I have a call to a URL and receive back a 0 or 1 on fail or success.I have my data in a NSMutableData *data; object.

I have a call to a URL and receive back a 0 or 1 on fail or success. I have my data in a NSMutableData *data; object.

I get the data, but now wa开发者_StackOverflow中文版nt to see if it's a 1 or 0. How do I do this? Do I need to get the bytes?

Thanks


You will need to convert the NSData to an NSString first. Then you can use the intValue method on NSString to convert it to an integer.

For example:

NSString* response = [[[NSString alloc] initWithData: data encoding: 
    NSASCIIStringEncoding] autorelease];
int value = [response intValue];
0

精彩评论

暂无评论...
验证码 换一张
取 消