简体   繁体   English

NSMutableData转换为Int

[英]NSMutableData to Int

I have a call to a URL and receive back a 0 or 1 on fail or success. 我有一个URL调用,失败或成功返回0或1。 I have my data in a NSMutableData *data; 我将数据存储在NSMutableData * data;中; object. 宾语。

I get the data, but now want to see if it's a 1 or 0. How do I do this? 我得到了数据,但是现在想看看它是1还是0。我该怎么做? Do I need to get the bytes? 我需要获取字节吗?

Thanks 谢谢

You will need to convert the NSData to an NSString first. 您首先需要将NSData转换为NSString Then you can use the intValue method on NSString to convert it to an integer. 然后,您可以在NSString上使用intValue方法将其转换为整数。

For example: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM