ich eine API bin mit JSON-Daten in Objektdaten, besuchen Sie bitte die API verwende ich Please Visit the API page which I am usingErste Fehler beim JSON-Daten konvertieren Objekt in iOS
Hier ist die Schnapp meines Codes mit markierten Fragen zu konvertieren Issues
und hier ist der Rohcode
-(void) retrieveData{
NSURL * url = [NSURLURLWithString:getDataUrl];
NSData * data = [NSData dataWithContentsOfURL:url]; jsonArray = [NSJSONSerialization JSONObjectWithData:data options: kNilOptions error:nil]; NSLog(@"JsonArray %@", jsonArray); //setup yougaArray yougaArray = [[NSMutableArray alloc] init]; //Loop through our jsonArray for (int i = 0; i<jsonArray.count; i++) { NSString * yId = [[[[jsonArray objectAtIndex:i]objectForKey:@"data"]objectAtIndex:@"categories"]objectForKey:@"id"]; // NSString * yId = [[jsonArray objectAtIndex:i]objectForKey:@"id"]; NSString * yName = [[[[jsonArray objectAtIndex:i]objectForKey:@"data"]objectAtIndex:@"categories"]objectForKey:@"name"]; NSString * yDescription = [[[[jsonArray objectAtIndex:i]objectForKey:@"data"]objectAtIndex:@"categories"]objectForKey:@"description"]; NSString * yImage = [[[[jsonArray objectAtIndex:i]objectForKey:@"data"]objectAtIndex:@"categories"]objectForKey:@"image"]; //Add the city object to our citiesArray [yougaArray addObject:[[Youga alloc]initWithYougaId:yId andYougaName:yName andYougaDescpription:yDescription andYougaImage:yImage]]; } [self.tableView reloadData]; }
'objectAtIndex: @" Kategorien "' => Warum setzt man einen NSString dort? Außerdem müssen Sie die Struktur von JSON verstehen, bevor Sie versuchen, es zu analysieren. – Larme
können Sie 'NSLog (@" JsonArray% @ ", jsonArray);'] –
können Sie übergeben den Ganzzahlwert in der [arrayName objectAtIndex: 0] wie dieser Zugriff auf das Array –