2

我无法将 JSON 保存到NSCachedURLResponse.

这是我的代码:

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

我知道这段代码没有实际错误,但它会导致 JSON 格式问题。通过保存operation.responseoperation.responsedata导致 JSON 被格式化,"feed":而不是feed =.

在保存它之前,我已经打印了responseObject哪个是 JSON,就像feed =. 所以我用原始格式保存responseObject到的问题。NSCachedURLResponse

我怎样才能做到这一点?

4

0 回答 0