Invalid JSON Data After fetchRecentPhotos Signature Updated

From pages 699-700 in the iOS edition of the text, we change the signature of the fetchRecentPhotos method in order to return the number of photos being sent back by the Flickr server. When I made this change, I got the following output in the console:

While I know that this message should happen when a change to the Flickr API happened, it seems unlikely it happened within a few minutes. Before this change, I was getting a return of correctly formed JSON data.

Here is my code for fetchRecentPhotos:

func
    fetchRecentPhotos( completion completion: (PhotosResult) -> Void )    {
        
        let url = FlickrAPI.recentPhotosURL()
        
        let request = NSURLRequest(URL: url)
        
        let task = session.dataTaskWithRequest(request) {
            
            (data, response, error) -> Void in
            
            let result =
                self.processRecentPhotosRequest(data: data,
                                               error: error)
            
            completion(result)
            
        }   // end task
        
        task.resume()
        
    }   // end fetchRecentPhotos()

Any idea of what might be causing this would be greatly helpful. Thanks. :confused:

Looks like you’re missing the “in” after Void. That might be it.

Hello,

I was wondering if you were able to find a solution to your problem? I’m experiencing the same difficulties with the failure state showing citing an InvalidJSONData rather than the number of photos retrieved. To ensure it wasn’t the API key problem, I created a new key and tried it out but am still experiencing the same problems.

Thanks

I’ve managed to solve the issue. There was a problem with my code when parsing the data in the photosFromJSONObject method.

I had the same issue: the error I made was in the photoFromJSONObject function where I misspelled “dateTaken” instead of “datetaken”. To be more precise: “dateString = json[“dateTaken”] as? String,…” and corrected with: “dateString = json[“datetaken”] as? String,…” Maybe you made a similar error in that function as I did :smile:

This is awesome. Thanks so much @rolfino, I would have spent hours looking for the bug. You taking the time to post your finding saved so much time :pray:t4:

Hi avog,

You are welcome!

:wink: