I have received some data in base64string format from JSON pasring in iphone. Now i want that data to store or decode in String. I have user Base64 class. It return me null value. so pls help me!!!
2 Answers
I hope it will helpful to you
NSString *decodeString = @"Raja";
Encode String
NSData *encodeData = [decodeString dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [encodeData base64EncodedStringWithOptions:0];
NSLog(@"Encode String Value: %@", base64String);
Decode String
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0];
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
NSLog(@"Decode String Value: %@", decodedString);
-
this code works well But in my case i get xml response from server which are already in base64 encoded .I have decode that data but when i use this method it returns null. can anybody suggest me tackle this problem ?? Feb 20, 2015 at 7:14
-
-
this decoded code contain sHTML code CgoKPCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwvL0VOIj4KPCEtLSA8IURP Q1RZUEUgSFRNTCBQVUJ......0bWw+Cg== Feb 20, 2015 at 8:59
-
try with constant data same as in xml response through check it working ?– codercatFeb 20, 2015 at 9:01
-
base64decode.org check with this url. your response code is decoded i had got html string. check with your xml response @amitgupta– codercatFeb 20, 2015 at 9:04
Try to use like this..First you need to get this base64 library
https://github.com/l4u/NSData-Base64
And then import this file
#import "NSData+Base64.h"
NSData *data = [NSData dataFromBase64String:baseString];
NSString *convertedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
I hope it helps.