2

I am having trouble with saving JSON to NSCachedURLResponse.

This is my code:

 operation.responseSerializer = AFJSONResponseSerializer()
 operation.setCompletionBlockWithSuccess({ (operation, responseObject) -> Void in  
    var cachedResponse = NSCachedURLResponse(response: operation.response,
        data: operation.responseData)
    NSURLCache.sharedURLCache().storeCachedResponse(cachedResponse, forRequest: request)
 })

I know that this code has no actual error but it's causing a JSON format problem. By saving operation.response and operation.responsedata its causing the JSON to be formatted like "feed": instead of feed =.

I've printed the responseObject which is the JSON before saving it was like feed =. so my problem with saving the responseObject into NSCachedURLResponse with its original formatting.

How can I achieve this?

clemens
  • 16,716
  • 11
  • 50
  • 65
AaoIi
  • 8,288
  • 6
  • 45
  • 87
  • Well, you are trying to print the raw data, and you are looking for string json I guess you should use `NSJSONSerialization.JSONObjectWithData(receivedData,options:NSJSONReadingOptions.AllowFragments,nil);` to get the json object. – iphonic Jul 23 '15 at 09:18

0 Answers0