AFNetworking 中的错误响应解析

Wrong response parsing in AFNetworking

AFNetworking 收到正确响应,但解析 returns 错误。我明白了,我在manager里设置错了,但是看不懂,这就对了。

我的代码:

manager = [[AFHTTPSessionManager alloc] initWithBaseURL:kAuthorizationUrl];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/x-plist",nil];
[manager POST:@"someURL" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
    NSLog(@"");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    NSLog(@"");
}];

返回错误:

"No value for key in object around character 35."

邮递员的回复body:

{
"featureAppleTVSynchronisation" = "false";
"featureDirectPlay" = "true";
"googleLoginSwitchOn" = "true";
}

响应headers:

Accept-Ranges →bytes
Access-Control-Allow-Credentials →true
Access-Control-Allow-Methods →GET, POST, OPTIONS
Connection →keep-alive
Content-Encoding →gzip
Content-Type →application/x-plist; charset=UTF-8
Date →Tue, 18 Oct 2016 19:57:05 GMT
Server →Apache/2.4.6 (CentOS)
Transfer-Encoding →chunked
Vary →Accept-Encoding
X-Varnish-Retries →0
cache-control →private, no-cache, no-store, must-revalidate, max-age=0
expires →Tue, 18-Oct-2016 19:00:28 GMT

好的,我找到了解决方案: 右码

manager = [[AFHTTPSessionManager alloc] initWithBaseURL:kAuthorizationUrl];
// Attention please! Here is what I changed!
manager.responseSerializer = [AFPropertyListResponseSerializer serializer];
// End
[manager POST:@"someURL" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject){
    NSLog(@"");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    NSLog(@"");
}];