UIImage to NSDate to NSString to JSON String is giving null value

Go To StackoverFlow.com

-3

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!

2012-04-03 21:22
by user181248
One thing you maybe should ask yourself is whether you want to transmit the images themselves or their URLs/name. Two entirely different things - Hot Licks 2012-04-03 21:29
i need to transfer the entire image into a json string because it gonna sync into a sql server later but i realize that it is getting the app so laggy, thanks for the down reputation by the way it is because i am noob i come here so be respectfull pleas - user181248 2012-04-03 21:38
i don't have time to write a book.. - user181248 2012-04-03 21:39
Wasn't me. Your question is naive, but not thoughtless - Hot Licks 2012-04-03 21:48
ok thanks i did convert the uiimage with base64string encoding but i am kind of new to those thing, what is the best solution to put a uiimage that will go into a json string and finally into a sql server - user181248 2012-04-03 22:02
You can either store the Base64 version in the server as a character string, or decode it to binary and store it as a "blob". Or it can be stored in a separate file on the server and the name of the file is placed in the SQL DB - Hot Licks 2012-04-03 22:30


2

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.)

2012-04-03 21:25
by Hot Licks
well thanks it works like a charm man - user181248 2012-04-03 22:00
Ads