0

I'm receiving some JSON data from a webservice, which includes an image represented as a Sting. How can I convert this string into an image?

The JSON data is in an NSDictionary, and the Image data is the Object form the "Content"-key:

if let newBannerContentString = newBanner.objectForKey("Content") as? String {
    let someImage = UIImage(contentsOfFile: newBannerContentString)
}

This returns nil to someImage.

1 Answer 1

2

If string is base64 encoded you could create NSData from that string and image from that data.

if let newBannerContentString = newBanner.objectForKey("Content") as? String {
    let data = NSData(base64EncodedString: newBannerContentString, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters);
    let someImage = UIImage(data: data!);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.