将NSData转换为NSString表示失败 [英] Converting NSData to an NSString representation is failing

查看:206
本文介绍了将NSData转换为NSString表示失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSData对象,我试图变成一个NSString使用下面的代码行:

I have an NSData object which I am trying to turn into an NSString using the following line of code:

NSString *theData = [[NSString alloc] initWithData:photo encoding:NSASCIIStringEncoding];

不幸的是,我得到以下结果,而不是我想要的二进制输出这里?);

Unfortunately I am getting the following result, instead of my desired binary output (can I expect a binary output here?);

ÿØÿà

$ b b

我会感谢任何帮助。

谢谢。 Ricky。

I'd appreciate any help.
Thanks. Ricky.

推荐答案

如果你想将一些任意的二进制数据转换成一个可读的字符串(例如,值),您使用的方法错误。您正在做的是将数据本身解释为ASCII编码的字符串。

If you want to transform some arbitrary binary data into a human readable string (for example, of a series of hex values) you are using the wrong method. What you are doing is interpreting the data itself as a string in ASCII encoding.

要将数据记录到文件或标准输出,可以使用 [数据描述]

To simply log the data to a file or to stdout, you can use [theData description].

这篇关于将NSData转换为NSString表示失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆