我正在使用base64encoding将UIImage发送到服务器,然后在另一端我收回它,将base64encodedstring转换为NSData然后尝试将我的图像恢复到UIImageView上。
一切正常工作发送Base64encodedString并接收它,但当我将NSData转换回UIImage时,它抛出以下异常
- [__ NSArrayI dataUsingEncoding:allowLossyConversion:]异常与Base64编码一起提交
这是我用于发布图像的代码:
img=mainImage.image; NSData *imgdata=UIImagePNGRepresentation(img); NSString *imgstring=[imgdata base64EncodedString]; NSString *post =[[NSString alloc] initWithFormat:@"gid=%@&image=%@",[lblgid text],imgstring]; NSLog(@"PostData: %@",post); NSURL *url=[NSURL URLWithString:@"http://www.abcd/updategameimage.php"];以下是接收端的代码
NSString *imgStr=[abc valueForKey:@"image"]; NSLog(@"%@",imgStr); NSData *imgdata=[NSData dataWithBase64EncodedString:imgStr]; imge = [UIImage imageWithData:imgdata]; [imgview setImage:imge];这里abc是NSMutableArray
I am using base64encoding for sending an UIImage to the server and then on the other end i am getting it back, converting the base64encodedstring in to NSData then trying to get my image back on an UIImageView.
Everything working fine sending the Base64encodedString and receiving it but when i am converting the NSData back in to UIImage it is throwing the following exception
-[__NSArrayI dataUsingEncoding:allowLossyConversion:] exception is comming with Base64 encoding
this is the code i am using for posting the image:
img=mainImage.image; NSData *imgdata=UIImagePNGRepresentation(img); NSString *imgstring=[imgdata base64EncodedString]; NSString *post =[[NSString alloc] initWithFormat:@"gid=%@&image=%@",[lblgid text],imgstring]; NSLog(@"PostData: %@",post); NSURL *url=[NSURL URLWithString:@"http://www.abcd/updategameimage.php"];And following is the code at receiving end
NSString *imgStr=[abc valueForKey:@"image"]; NSLog(@"%@",imgStr); NSData *imgdata=[NSData dataWithBase64EncodedString:imgStr]; imge = [UIImage imageWithData:imgdata]; [imgview setImage:imge];Here abc is NSMutableArray
最满意答案
你确定abc是一个mutableArray吗?
因为您正在向它发送一个valueForKey:方法。 这是由NSObject实现的KVC方法,将此消息发送给它是没有意义的。
如果您打算将objectForKey:方法发送给它 - 那么这将是您发送到字典而不是数组的消息。
而且,你得到的错误:
- [__ NSArrayI dataUsingEncoding:allowLossyConversion:]异常与Base64编码一起提交
告诉你NSArray没有响应dataUsingEncoding:allowsLossyConversion: messages - 这是一个NSString对象的方法。
我认为你对你的对象类型感到困惑,需要更好地处理什么是什么。
Are you sure abc is a mutableArray?
Because you are sending it a valueForKey: method. This is a KVC method implemented by NSObject and it doesn't make sense to send it this message.
If you meant to send it the objectForKey: method instead - then that would be a message that you send to dictionaries, not arrays.
And, the error that you are getting:
-[__NSArrayI dataUsingEncoding:allowLossyConversion:] exception is comming with Base64 encoding
is telling you that an NSArray does not respond to dataUsingEncoding:allowsLossyConversion: messages - which is a method for NSString objects.
I think you are getting confused with your object types and need to get a better handle on what is what.
更多推荐
发布评论