ios - Converting from JSON string to UIImage always gives null? -


i kind of json:

note: put dots in "content" because long byte array abd explain situation.

{    "id":"53abc6a7975a9c10c292f670",    "nfcid":"testse",    "company":"test",    "qrid":"testvalue",    "address":"ajs;ldfh",    "mimetype":"image",    "url":"",    "content":"ivborw0kggoaaaansuheugaa....." } 

and im trying json , diplay information "content" field has byte array converted on server image byte array.

i use code in xcode convert bytes nsdata, uiimage able display in uiimageview:

    nsdata *dataimage = [jsonarray[key] datausingencoding:nsutf8stringencoding];     nslog(@"data = %@", dataimage);     uiimage *img = [uiimage imagewithdata:dataimage];     nslog(@"img = %@", img); 

the image gives me null.although, data give me array of data.

i tried kinds of encodings nsdata parameters also:

datausingencoding:nsasciistringencoding datausingencoding:nsutf8stringencoding datausingencoding:nsutf16stringencoding datausingencoding:nsutf32stringencoding 

i've used code before

    nsurl *url = [nsurl urlwithstring:[nsstring stringwithformat:@"data:image/png;base64,%@",jsonarray[key]]];     nsdata *imagedata = [nsdata datawithcontentsofurl:url];     uiimage *img = [uiimage imagewithdata:imagedata]; 

note initwithbase64encodedstring available ios7 onwards


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -