gpt4 book ai didi

ios - 错误域=NSCocoaErrorDomain 代码=3840 "The operation couldn’ 使用 AFNetworking 完成

转载 作者:IT王子 更新时间:2023-10-29 08:02:17 26 4
gpt4 key购买 nike

我正在使用 AFNetworking 库通过 POST 方法在服务器上发布数据。

以下是我的代码

- (void) callLoginAPI:(NSDictionary *)dictProfile{
// 1
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:[dictProfile valueForKey:@"name"], @"username",
[dictProfile valueForKey:@"first_name"],@"first_name",
[dictProfile valueForKey:@"last_name"],@"last_name",
[dictProfile valueForKey:@"email"],@"email",
[dictProfile valueForKey:@"birthday"],@"dob",
[dictProfile valueForKey:@"gender"],@"gender",
[[dictProfile valueForKey:@"location"] valueForKey:@"name"],@"location",
[dictProfile valueForKey:@"timezone"],@"timezone",
@"",@"language",
[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",[dictProfile valueForKey:@"id"]],@"profile_pic_url",
@"",@"cover_pic_url",nil];



AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];



[manager POST:@"http://10.1.81.35:8000/api/login/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}

但我收到以下响应错误

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x797f2620 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

我不明白代码有什么问题。

最佳答案

问题来自响应解析。您正在尝试反序列化 JSON 响应(必须包含在 NSArrayNSDictionary 中)但是您的响应不是上面(很可能是一个简单的字符串)。

此外,尝试将“允许片段”设置为响应序列化程序。

AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

关于ios - 错误域=NSCocoaErrorDomain 代码=3840 "The operation couldn’ 使用 AFNetworking 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26233611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com