我有一个 NSdata 对象,其中填充了一堆以十六进制格式设置的信息.我正在尝试将其转换为正确的字符串表示形式,但正在努力取得任何成功.
I have a NSdata object that is populated with a bunch of information thats formated in hex.. I am trying to convert it into its proper string representation but am struggling to have any success.
我尝试过的一件事是简单地将其放入 NSString 中,然后使用特殊字符标识符 thingy 将其 NSLog .. 忘记了单词 (%02x),但是要做到这一点,我将其编码为 NSUTF16 ..不想做..我很想看看我得到的数据到底是什么,看起来像一个 NSString.
One thing I have tried is to simply put it into a NSString and then NSLog it with a special character identifier thingy.. forgot the word (%02x), However to do this I am encoding it to NSUTF16.. which i dont want to do.. I mearly want to see exactly whats the data I am getting looks like as a NSString.
我这样做的原因是因为我稍后在我的代码中遇到了一些编码问题,我不确定是因为我收到的数据不正确还是我在处理的某个时候把它塞满了
The reason I am doing this is because I am having some issues with my encoding later on in my code and im not sure if its because the data I am receiving is incorrect or me stuffing it up at some point when I am handling it.
任何帮助将不胜感激.
推荐答案您可以像这样获得 NSData 的字符串表示:
You can get a string representation of your NSData like so:
NSData *data = (your data) NSString *string = [NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding];这是否回答了您的问题?
Does that answer your question?
更多推荐
如何将填充有十六进制值的 NData 转换为 NSString
发布评论