【问题标题】:JSON parse error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)JSON 解析错误:Error Domain=NSCocoaErrorDomain Code=3840 “操作无法完成。(Cocoa 错误 3840。)
【发布时间】:2014-09-30 06:04:10
【问题描述】:

我正在使用 sendAsynchronousRequest 请求到服务器以从中获取数据。当我在浏览器中检查 Web 服务时,它工作正常并且能够得到响应。但是当我从 Xcode 发送请求时,我无法在 Xcode 中获得响应。我正在使用以下代码发送响应。

NSString *strurl=[NSString stringWithFormat:@"%@/rest_stores/storeCategoryListByStoreId/%@.json",baseurl,[[NSUserDefaults standardUserDefaults] valueForKey:@"storeid"]];
    NSURL *url = [NSURL URLWithString:strurl];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {
         NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

         NSError *jsonError;
         NSData *trimmedData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
         NSDictionary *json = [NSJSONSerialization JSONObjectWithData:trimmedData options:NSJSONReadingAllowFragments error:&jsonError];
         if (jsonError)
         {
             NSLog(@"JSON parse error: %@", jsonError);
             [HUD hide:YES];
             return;
         }
}];

请求花费太多时间来加载响应,之后我得到的响应数据为空。以及 Xcode 向我显示的错误。

JSON parse error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value.) UserInfo=0x112e4d390 {NSDebugDescription=No value.}

直到昨天它工作正常。但是当我今天开始时。我正面临这个有线问题。我无法获得项目的任何 Web 服务的响应,但在浏览器中一切正常。

【问题讨论】:

  • 需要更多信息。在行之前设置断点:NSError *jsonError; 并告诉我们您在下一个变量中看到的内容:response, data, error?
  • 我在这里提到了错误。并且响应和数据都是零。
  • 如果响应和数据为零,则意味着一台服务器没有正确响应。通过 REST any utils 测试 REST URL API。
  • @Bimawa 感谢您的关注。我解决了我的问题,可能是 Xcode 问题。我只是从 Organizer 中删除项目并重置模拟器。现在它工作正常。
  • 一点也不,是真的,编译只看到所有项目一次,所有下一次编译的编译只更改文件,以节省时间。有时我们会遇到问题,看起来像您的情况。有时在帮助之前清除项目:)

标签: ios objective-c json xcode web-services


【解决方案1】:

我解决了我的问题,可能是 Xcode 问题。我只是从 Organizer 中删除项目并重置模拟器。现在它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 2015-07-13
    • 2014-11-02
    • 1970-01-01
    • 2020-01-26
    • 2016-01-30
    相关资源
    最近更新 更多