0

アプリケーション内の別の最上位 JSON オブジェクトにアクセスするのに苦労しています。計画は、Instagram からデータをロードすることです (これは機能します) が、必要なトップレベルをカウントすることはありません。

JSON ドキュメントはここにあります ( http://pastebin.com/0Z4vBjRn ) 基本的に、ページネーション、メタ、データ (データ ビットが必要な場所) の 3 つのトップレベル オブジェクトがあります。

これは今のところ私のコードです:

        - (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view.


            // Viser "spinner" for å symbolisere nettverkstrafikk.
            [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

            // URL til JSON filen
            NSURL *newsUrl = [NSURL URLWithString:@"https://api.instagram.com/v1/tags/beer/media/recent?client_id=client_key"];

            //URL Requestobjekt for å kontrollere tilkobling
            NSURLRequest *newsRequest = [NSURLRequest requestWithURL:newsUrl];
            [[NSURLConnection alloc]initWithRequest:newsRequest delegate:self];

        }

        - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
            [rawImages setLength:0];
            rawImages = [[NSMutableData alloc] init];
        }

        - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
            [rawImages appendData:data];
        }

        - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            images = [[NSArray alloc]init]; // Updated
            images = [NSJSONSerialization JSONObjectWithData:rawImages options:0 error:0];
            [self.collectionView reloadData];
        }

        - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
            UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Feil" message:@"Det har oppstått en feil ved nedlastingen av data. Dobbeltsjekk at du er koblet til internett" delegate:nil cancelButtonTitle:@"Fortsett" otherButtonTitles:nil];
            [errorView show];
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        }





        - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
            return 1;
        }

        - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

            return [images count];

        }

        - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

            UICollectionViewCelle *cell = (UICollectionViewCelle *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];


            cell.imageView.image = [UIImage imageNamed:@"eksempel.jpg"];

            return cell;
        }

明らかに、カウント部分は機能しません (3 つしか返されません)。しかし、「データ」オブジェクト内のすべてのオブジェクトをカウントするにはどうすればよいでしょうか? すべてのヘルプは大歓迎です! 私はグーグルをしましたが、私が探しているものを正確に見つけることができないようです.

4

0 に答える 0