Fehler beim Parsen der Echo Nest API JSON mit Objective-CIOS

Programmierung für iOS
Guest
 Fehler beim Parsen der Echo Nest API JSON mit Objective-C

Post by Guest »

Ich bin relativ neu in Objective-C, aber ich habe JSON schon einmal mit JavaScript geparst.

Ich habe diesen Code in meinem viewDidLoad

Code: Select all

NSURL *songsURL = [NSURL URLWithString:@"http://developer.echonest.com/api/v4/song/search?api_key=UVHRIOB9ISTKAAQ0R&format=json&results=1&combined=everybody%20dance%20now&bucket=id:7digital-UK&bucket=tracks&limit=true"];

NSData *jsonData = [NSData dataWithContentsOfURL:songsURL];

NSError *error = nil;

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

NSDictionary *item = [dataDictionary objectForKey:@"response"];
NSLog(@"%@", item);
NSDictionary *songs = [item objectForKey:@"songs"];
NSLog(@"%@", songs);
NSDictionary *songTitle = [songs objectForKey:@"title"];
NSLog(@"Title= %@", songTitle);
und es funktioniert alles, bis ich versuche, die Songtitel abzurufen.

Nachdem ich die Songs abgerufen habe, Das JSON sieht so aus:

Code: Select all

(
{
"artist_foreign_ids" =         (
{
catalog = "7digital-UK";
"foreign_id" = "7digital-UK:artist:2060042";
}
);
"artist_id" = ARKSHFP12D5CD74F5D;
"artist_name" = "Everybody Left";
id = SOWGJIF143A016B701;
title = "We Are Everybody Left";
tracks =         (
{
catalog = "7digital-UK";
"foreign_id" = "7digital-UK:track:32612792";
"foreign_release_id" = "7digital-UK:release:3062491";
id = TRZNPMZ1429AA0B7CE;
"preview_url" = "http://previews.7digital.com/clip/32612792";
"release_image" = "http://artwork-    cdn.7static.com/static/img/sleeveart/00/030/624/0003062491_200.jpg";
}
);
}
)
Ich habe versucht, andere Werte abzurufen, z. B. Titel mithilfe von NSDictionary *tracks = [songs objectForKey:@"tracks"];, aber ich erhalte immer noch die Fehlermeldung:

Code: Select all

2014-08-29 01:54:07.612 khord[9530:60b] -[__NSCFArray objectForKey:]: unrecognized selector sent to     instance 0x987c450
2014-08-29 01:54:07.614 khord[9530:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x987c450'
Könnte mir bitte jemand eine Lösung anbieten, wie ich dieses JSON richtig analysieren soll? Ich habe das Gefühl, dass ich die Datentypen nicht richtig verstehe.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post