JSON Abfrage

  • JSON Abfrage

    Hallo Forum-Mitglieder,

    ich versuche derzeit einen JSON auszuwerten. das JSON sieht folgender maßen aus.

    Quellcode

    1. [b] data = {[/b]
    2. [b] movies = ([/b]
    3. [b] {[/b]
    4. [b] additional = {[/b]
    5. [b] "watched_ratio" = 0;[/b]
    6. [b] };[/b]
    7. [b] certificate = "";[/b]
    8. [b] id = 5;[/b]
    9. [b] "last_watched" = 0;[/b]
    10. [b] "mapper_id" = 9;[/b]
    11. [b] "metadata_locked" = 0;[/b]
    12. [b] "original_available" = "2008-09-25";[/b]
    13. [b] "sort_title" = "Test";[/b]
    14. [b] title = "Test";[/b]
    15. [b] },[/b]
    Alles anzeigen

    Den JSON frage ich in XCODE wie folgt ab:

    Quellcode

    1. NSString *urlString = [NSString stringWithFormat:@"http://%@:%@/webapi/VideoStation/movie.cgi?api=SYNO.VideoStation.Movie&version=3&method=list&_sid=%@",ip,port,sid];
    2. NSURL *url = [NSURL URLWithString:urlString];
    3. NSURLRequest *request = [NSURLRequest requestWithURL:url];
    4. NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
    5. NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
    6. NSURLSessionDataTask *apiCall = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    7. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    8. NSLog(@"JSON: %@",json);
    9. NSLog(@"SID: %@", [[json objectForKey:@"data"] objectForKey:@"movies"]);
    10. }];
    11. [apiCall resume];
    Alles anzeigen

    Ich komme mit der Abfrage bis zum Punkt movies. Ich möchte aber Beispielsweise title abfragen. Wenn ich dann die Zeile ändere in "NSLog(@"SID: %@", [[[json objectForKey:@"data"] objectForKey:@"movies"] objectForKey:@"title"]);" stürzt das Programm ab.
    Hat vielleicht jemand Erfahrung mit JSON.


    Mit freundlichen Grüssen
    David
  • Kann es sein das :

    [[[json objectForKey:@"data"] objectForKey:@"movies"] kein dictionary sundern ein array ist ??


    Log das doch mal mit class. Du würdest dann mit

    [[[json objectForKey:@"data"] objectForKey:@"movies"]objectAtIndex:0] das dictionary kriegen und mit :

    [[[[json objectForKey:@"data"] objectForKey:@"movies"]objectAtIndex:0]valueForKey:"title"]

    Gruß

    Helmut