问题
I have this weird problem about NSDictionary and base64 String and I cannot locate where the problem is.
Here's the code:
NSData *pictureData = [[NSData alloc]init];
pictureData = UIImagePNGRepresentation([UIImage imageNamed:@"logo"]);
NSString * picture = [pictureData base64EncodedString];
picture = [picture stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
if(picture == nil){
picture = @"";
}
self.postDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:picture,@"picture",@"some text",@"caption", nil];
What happens is If I log the string,"picture", the log is very fine and okay. But when I try logging the dictionary it says something like this
{
caption = "some text";
picture = "iVBORw0KGgoAAAANSUhEUgAAAoAAAABYCAIAAADqXdEfAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAHGlET1QAAAACAAAAAAAAACwAAAAoAAAALAAAACwAAI2cl9ZnZQAAQABJREFUeAGM3euyXVl5HmDdWa7EuYec7sDBlZSrErtS+RP/clXiuCr+YzAYaKDpBmPABpr0S...and it gets CUT some part then... picture = iVBORw0KGgoAAAANSUhEUgAAAoAAAABYCAIAAADqXdEfAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAHGlET1QAAAACAAAAAAAAACwAAAAoAAA..till the end of the base64 string";
}
The problem is the word "picture" as key is found also in the string object inside picture. The base64 string was cut first then followed by the picture = then the full text of the base64 string
Does not happen on simulator but happens on device. Before was just fine. I didn't changed anything on the codes. and I cannot change the NSDictionary codes also.
If I don't log it it's still like that when the web service receives the POST.
So if you guys can help me find a way. Thanks :)
来源:https://stackoverflow.com/questions/17985121/nsdictionary-base64-string-logs