iOS 7+中的Base64解码

我已经NSString使用NSDataiOS7中添加的Class new API 编码了text()。


使用这个


- (NSData *)dataUsingEncoding:(NSStringEncoding)encoding;  

这是我的代码


NSString *base64EncodedString = [[myText dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0];


NSLog(@"%@", base64EncodedString);

我正在寻找解码


开心每一天1111
浏览 598回答 2
2回答

回首忆惘然

迅捷3+let plainString = "foo"编码方式let plainData = plainString.data(using: .utf8)let base64String = plainData?.base64EncodedString()print(base64String!) // Zm9v解码if let decodedData = Data(base64Encoded: base64String!),&nbsp; &nbsp;let decodedString = String(data: decodedData, encoding: .utf8) {&nbsp; print(decodedString) // foo}迅捷<3let plainString = "foo"编码方式let plainData = plainString.dataUsingEncoding(NSUTF8StringEncoding)let base64String = plainData?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))print(base64String!) // Zm9v解码let decodedData = NSData(base64EncodedString: base64String!, options: NSDataBase64DecodingOptions(rawValue: 0))let decodedString = NSString(data: decodedData, encoding: NSUTF8StringEncoding)print(decodedString) // foo目标CNSString *plainString = @"foo";编码方式NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];NSString *base64String = [plainData base64EncodedStringWithOptions:0];NSLog(@"%@", base64String); // Zm9v解码NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0];NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];NSLog(@"%@", decodedString); // foo&nbsp;

BIG阳

如果您想编写后备代码,则从一开始就在iOS中存在从base64进行解码的警告NSURL:NSURL *URL = [NSURL URLWithString:&nbsp; &nbsp; &nbsp; [NSString stringWithFormat:@"data:application/octet-stream;base64,%@",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;base64String]];return [NSData dataWithContentsOfURL:URL];
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

iOS