iphone - Putting Byte value into NSDictionary [iOS] -


i have post web service, need send image in byte array, , need send post parameters in json format, have created nsdictionary. issue how can assign object key in dictionary byte, tried doing , application crashes while creating nsdictionary. explaining each steps code easy understanding of y question below :-

here code converting image byte format :-

nsdata *data = [nsdata datawithcontentsoffile:filepath]; nsuinteger len = [data bytes]; byte *bytedata = (byte*)malloc(len); memcpy(bytedata, [data bytes], len); 

so, have byte contain image in byte array, want assign object nsdictionary. here code,

nsdictionary *dictjson = [nsdictionary dictionarywithobjectsandkeys: bytedata, @"photo", nil]; 

now application crashes in above line creating dictjson object, there way can pass byte nsdictionary?

also, question, how can nslog bytedata?

please me.

thanks in advance!

if want sent image data json array containing bytes numbers, have create array "manually", there not built-in function:

nsdata *data = ... // image data const unsigned char *bytes = [data bytes]; // no need copy data nsuinteger length = [data length]; nsmutablearray *bytearray = [nsmutablearray array]; (nsuinteger = 0; < length; i++) {     [bytearray addobject:[nsnumber numberwithunsignedchar:bytes[i]]]; } nsdictionary *dictjson = [nsdictionary dictionarywithobjectsandkeys:               bytearray, @"photo",               nil]; nsdata *jsondata = [nsjsonserialization datawithjsonobject:dictjson options:0 error:null]; 

the json data like

{"photo":[byte0, byte1, byte2, ...]} 

so perhaps server expects. note ineffective (in terms of space) way send image data (compared base64 example).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -