我用
[[NSData alloc] initWithBase64EncodedString:content options:0];
加载通过网络传递的二进制数据,作为 JSON 对象的键。有时它可以工作,但在其他情况下它会失败,例如 this string .
这是由 NSData
本身在另一端创建的字符串:
[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
我必须通过任何选项,为什么它返回 nil?字符串的长度是 4 的倍数并且没有奇怪的字符,所以我不明白它为什么会失败?
我再次阅读了文档,特别是这部分:
The default implementation of this method will reject non-alphabet characters, including line break characters. To support different encodings and ignore non-alphabet characters, specify an options value of NSDataBase64DecodingIgnoreUnknownCharacters.
它拒绝字符的事实意味着它显然会因为这些字符而拒绝整个字符串,因为当我将 NSDataBase64DecodingIgnoreUnknownCharacters
添加到初始化程序选项时,它甚至可以使用提到的字符串。
关于ios - NSData 在传递某些 base64 字符串时返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33112555/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |