i need to put images into a json string.. first is that possible?
i did :
NSData *data = UIImagePNGRepresentation(img);
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[myArrayPhoto addObject:string];
if i do this code.. it crash but if i make
[myArrayPhoto addObject:[NSString stringWithFormat:@"%@",string]];
it works but the image is NULL..
help
thanks!
To put an image into JSON you'd have to encode it as Base64 or some such and transmit it as character. Attempting to use UTF8 is doomed because the (basically random) data bytes in the image will contain the character equivalent of "
, {
, [
, :
, et al.
(And I'd add that it's probably a bad idea to transmit an image of any size as JSON. Rather you should use some file transfer protocol.)