0

I have a reponse from server as a json object and one of the keys stores an UIImage as Data. How could I get the value of this key?

What I have now:

let json = JSON(data: response.data!)
if json.count > 0 {
for (index , subJson):(String, JSON) in json {
    if let photoThumbString = subJson["photoThumb"].string {
                   if photoThumbString.characters.count > 0 {
                         let data = photoThumbString.data(using: .utf8)!
                         feedObject.pictureData = data
                   }
    }
}

But if I convert the Data object back to an UIImage , the image will be nil:

if let pictureData = currentFeedObject.pictureData {
        let image: UIImage? = UIImage(data: pictureData)
    }

Here is the json I am receiving (photo thumb value is very long, I put only a small part of it)

[
  {
    "id" : "26sb1f20-4c62-1se7-8478-03261423e36b",
    "photoThumb" : "\/9j\/4AAQSkZJRgABAQAASABIAAD\/4QBYRXhpZgAATU0AK\/KpWyIhsV0K74Y0XG4ZYk5yc1o3zNp8cbW\/BlBQ\/TisyL\/X2\/8Au\/1rS1z\/AFNt9T\/Sol8SNOp\/\/9k=",
    "author" : {
      "firstName" : "First Name",
      "lastName" : "Last Name",
      "admin" : false,
      "userPrincipal" : "xxxx"
    },
    "dateTime" : "2017-06-08T16:11:38.434",
    "hashtags" : [
        "#general"
    ],
    "content" : "ASDASDASD"
  }
]
Meeshoo
  • 129
  • 11

1 Answers1

0

Please tell me whether you are 100 percent sure that value of "photoThumb" is correct in JSON

I think that this post will be very useful for you

Robert
  • 3,790
  • 1
  • 27
  • 46
  • Indeed, meanwhile we started to investigate if the thumbnail is correctly generated on the server side. Thank you for your answer. – Meeshoo Jun 09 '17 at 12:02