2016-09-29 21 views
0

試圖從Instagram解析簡單的JSON數據,但堅持這個問題。 JSON數據返回在應用程序中被截斷,但通過我的mac上的瀏覽器,一切正常。Instagram的API json數據被截斷通過應用程序,但在瀏覽器中確定

試圖做很多不同的方式,但都是一樣的。

第一種方式:

NSURL *instaGetRecentOwnerPhotosURL = [NSURL URLWithString:@"https://api.instagram.com/v1/users/self/media/recent/?access_token=MY_PROPER_TOKEN"]; 
NSData *jsonData = [NSData dataWithContentsOfURL:instaGetRecentOwnerPhotosURL]; 

的另一種方式,assync:

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.instagram.com/v1/users/self/media/recent/?access_token=MY_PROPER_TOKEN"]]; 
__block NSDictionary *json; 
[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 
          json = [NSJSONSerialization JSONObjectWithData:data 
                    options:0 
                    error:nil]; 
          NSLog(@"Async JSON: %@", json); 
         }]; 

JSON數據恢復這樣的: screenshot of truncated json

絕對不知道什麼是錯的。

回答

0

它沒有被截斷。日誌只是顯示部分輸出。如果它真的被截斷了,它可能根本就不會被解析,或者只會有更少的條目。但數據解析。 json沒有錯。

順便說一句 - 做正確的錯誤檢查:

NSError *error = nil; 
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; 
if (json) { 
    // Data is good. Work with 'json' 
} else { 
    NSLog(@"Unable to parse JSON. Error: %@", error); 
} 
+0

謝謝!真的,新的XCode 8在真實設備上運行時沒有顯示整個json結果,但是在模擬器上運行時顯示整個結果。我發現它很奇怪。想想,可以在偏好設置中關閉此功能。 –

相關問題