You need to convert your UIImage to NSData, and then convert NSData to NSString, which will be a string representation of your base64 database.
Once you get NSString * from NSData *, you can add it to your dictionary in the @ "image" key
To convert NSData to base64 type NSString *, refer to the following link: How to make base64 encoding on iphone-sdk?
In a more pseudo-path, the process will look like this:
UIImage *my_image; //your image handle NSData *data_of_my_image = UIImagePNGRepresentation(my_image); NSString *base64StringOf_my_image = [data_of_my_image convertToBase64String]; //now you can add it to your dictionary NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:base64StringOf_my_image forKey:@"image"]; if ([NSJSONSerialization isValidJSONObject:dict]) //perform a check { NSLog(@"valid object for JSON"); NSError *error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; if (error!=nil) { NSLog(@"Error creating JSON Data = %@",error); } else{ NSLog(@"JSON Data created successfully."); } } else{ NSLog(@"not a valid object for JSON"); }
Codename lambda1
source share