2013-07-30 34 views
0

我在iOS應用程序上使用Facebook進行身份驗證,並使用以下方法獲取提要。 當我檢查它是否是有效的JSON對象,返回true,但如果我嘗試分析它,它給我的錯誤:NSJsonSerialzation不解析來自Facebook的結果 - 可可錯誤3840

Mistake: The operation couldn’t be completed. (Cocoa error 3840.) 

什麼能關於做什麼?這是什麼從服務器到達,完全有效的JSON - http://pastebin.com/ZwTnvi5g(通過NSLog得到它的結果)。

我該如何解決它,使nsjsonserialization正確解析它?

- (void) refreshButtonPressed 
{ 
    FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed"]; 
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

     NSError *mistake; 

     BOOL can = [NSJSONSerialization isValidJSONObject:result]; 

     NSLog(@"%d", can); 


     NSDictionary *first = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingAllowFragments error:&mistake]; 

     if (mistake) { 
      NSLog(@"Mistake: %@", [mistake localizedDescription]); 
     } 
    }]; 
} 
+1

向我們展示一些實際的JSON,而不是像你所說的那樣,是一個大型字典的'NSLog()'。 – CodaFi

+0

@CodaFi - 這是該完成處理程序獲取和無法轉換的id結果的NSLog。 – Dvole

+0

@CodaFi它打印我在pastebin上提供的文本,就是這樣,我沒有削減任何東西或添加任何東西 – Dvole

回答

1

實際上閱讀文檔可能在這裏有所幫助。

@param result   The result of the request. This is a translation of 
         JSON data to `NSDictionary` and `NSArray` objects. This 
         is nil if there was an error. 

它解析一切本身,我甚至不需要那樣做。所以它返回有效的NSDictionary或NSArray。