decode base64 string as UTF-8
I am using the base64 implementation at the bottom of this post.
If I use following code:
NSLog(@"decoded:%@",[[[NSString alloc] initWithData:[Base64 decode:@"8fEmIzEyNDA3OyYjMTI0MTE7"] encoding:NSUTF开发者_开发问答8StringEncoding] autorelease]);
I get decoded:(null)
However, if I use:
NSLog(@"decoded 1:%@",[[[NSString alloc] initWithData:[Base64 decode:@"8fEmIzEyNDA3OyYjMTI0MTE7"] encoding:NSASCIIStringEncoding] autorelease]);
I get decoded:ññぷほ
But I should get decoded:ññぷほ
What am I doing wrong?
Those are HTML character references. You'll need to decode further if you want raw text.
You should read this article by Matt Gallagher. At the bottom there is link with code for iOS if that is what you are after.
It provides an class extension to NSData which is you string is easily converted from and too.
精彩评论