Search code examples
objective-cjsonapiinstagram-apinsjsonserialization

Instagram API json data is truncated via app but ok in browser


Trying to parse simple JSON data from Instagram but stuck with this problem. JSON data returns truncated in application, but everything is ok via browser on my mac.

Tried to do that many different ways, but all the same.

First way:

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

Another way, 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 data returns like that: screenshot of truncated json

Absolutely have no idea what is wrong.


Solution

  • It's not truncated. The log simply only shows part of the output. If it was really truncated it either wouldn't have parsed at all or it would just have fewer entries. But the data did parse. There is nothing wrong with json.

    BTW - do proper error checking:

    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);
    }