NSMutableData 到 Int

发布于 2024-09-25 14:34:38 字数 123 浏览 0 评论 0原文

我调用了一个 URL,并在失败或成功时收到 0 或 1。我的数据位于 NSMutableData *data;目的。

我获取了数据,但现在想看看它是 1 还是 0。我该怎么做?我需要获取字节吗?

谢谢

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 want to see if it's a 1 or 0. How do I do this? Do I need to get the bytes?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2024-10-02 14:34:39

您需要首先将 NSData 转换为 NSString。然后,您可以使用 NSString 上的 intValue 方法将其转换为整数。

例如:

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

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文