【问题标题】:AFNetworking weird error on device, Working on Simulator设备上的 AFNetworking 奇怪错误,在模拟器上工作
【发布时间】:2013-07-28 15:34:44
【问题描述】:

这是我请求 JSON 的代码:

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request


                                  success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){


                                      NSArray *jsonArray =[JSON valueForKey:@"posts"];

                                      [self postsToAnnotations:[self jsonToPosts:jsonArray] andUserLocationLat:lat Lon:lon];


                                  }

                                  failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
                                      NSLog(@"response %@",JSON);

                                      NSLog(@"Failed %@",error);

                                      [_activityView removeFromSuperview];


}];

[operation start];
  }

它在 iPhone 5 的模拟器和我的设备 (iphone 4) 上运行良好我收到此错误: 错误域 = NSCocoaErrorDomain 代码 = 3840 “操作无法完成。(可可错误 3840。)”(JSON 文本没有以数组或对象开头,并且选项允许未设置片段。) UserInfo = 0x208b9a80 {NSDebugDescription = JSON 文本没有以数组或对象开头,并且没有设置允许片段的选项。}

【问题讨论】:

  • 这与 Xcode 完全无关。除此之外,您是否阅读错误消息?从中很清楚问题是什么,它甚至告诉你如何解决它。

标签: ios json afnetworking


【解决方案1】:

问题在于我无法看到服务器的回复,因为我使用的是 AFJSONRequestOperation。发送相同的请求 AFHTTPRequestOperation 后,我能够看到服务器使用“结果”字符串的回复。

【讨论】:

    猜你喜欢
    • 2021-10-15
    • 1970-01-01
    • 2012-08-19
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2013-10-08
    • 1970-01-01
    相关资源
    最近更新 更多