AFNetworking3.x Error Code:3840

2017-06-08  本文已影响167人  小北风sky

Error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

解决办法:

manager.requestSerializer = [AFHTTPRequestSerializer serializer];// 请求
manager.responseSerializer = [AFHTTPResponseSerializer serializer];// 响应
//转码
 NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
 ///AFNetworking 3.x
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];// 请求
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];// 响应
    
    [manager POST:urlString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        
        //转码
        NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

        
        NSLog(@"JSON: %@", string);
        
        
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        
        NSLog(@"Error: %@", error);
        
        
    }];
上一篇下一篇

猜你喜欢

热点阅读