My IOS app is retrieving a JSON Object containing a field "file" which is an image. This field is encoded by the server in Base 64
JSON Serialization: Optional({
file = "/9j/4AAQSkZJRgABAQAAAQABAAD/........
I would need to load this field in an UIImageView. I tried multiple ways without any success. here is an extract of my code:
let task = session.dataTaskWithRequest(request, completionHandler: { (data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
if (error == nil) {
let json: AnyObject?
let imageArray: NSData?
do{
try json = NSJSONSerialization.JSONObjectWithData(data!, options: [])
imageArray = json!["file"] as? NSData
print("JSON file: \(imageArray)")
}
catch
{
print("error Serialization")
return
}
but imageArray is nil...any idea how I can retrieve this field (Base 64 Byte array) and convert it in an UIImage ?