Alamofire4 jsonSerialization在响应中失败

时间:2016-11-01 21:41:02

标签: ios json swift3

我使用Alamofire4并且我在responseJson中有一个jsonSerializationFailed错误。 似乎Json没有很好地格式化响应:

AlmF Failure Reason: jsonSerializationFailed(Error Domain=NSCocoaErrorDomain
Code=3840 "Invalid value around character 0." UserInfo=
{NSDebugDescription=Invalid value around character 0.})
AlmF Underlying error: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})

以下是显示错误的代码:

case .responseSerializationFailed(let reason):
                    print("AlmF Response serialization failed: \(error.localizedDescription)")
                    print("AlmF Failure Reason: \(reason)")
                }

以下是

的debugPrint(响应)的结果
 .responseJSON { response in:

=>

 [Request]: http://myserver.com/Images.zip
 [Response]: <NSHTTPURLResponse: 0x60000003cde0> { URL: http://myserver.com.com/Images.zip } { status code: 200, headers {
"Accept-Ranges" = bytes;
Connection = close;
"Content-Length" = 117127;
"Content-Type" = "application/zip";
Date = "Tue, 01 Nov 2016 21:28:23 GMT";
Etag = "\"701a02b-1c987-534eb9a863980\"";
"Last-Modified" = "Fri, 10 Jun 2016 12:23:18 GMT";
Server = Apache;
"X-Powered-By" = PleskLin;

我应该在哪里格式化Json,我认为Alamofire这样做

编辑:

在使用Swift2的代码之前:

.response { _, _, _, error in
            if let error = error {
                SpeedLog.print("DownloadVC Failed with error: \(error)")
            } else {
                SpeedLog.print("DownloadVC zip downloaded")
}

0 个答案:

没有答案