0

cms から返されたこの json があり、それを分割して別の値を使用する必要があります。

{"nodes":
     [{"node":
        {"created":"14012013165204","lastupdated":"03042013133901","type":"News"}
     }]
}

私はJSONKitフレームワークを使用しています。これが私のコードです:

    NSString* theURL = [NSString stringWithFormat:@"http://testserver.com/content_lastupdate.json"];
    NSError* err = nil;
    NSURLResponse* response = nil;
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
    NSURL*URL = [NSURL URLWithString:theURL];
    [request setURL:URL];
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
    [request setTimeoutInterval:30];
    NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

    NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *resultsDictionary = [output objectFromJSONString];

    NSLog([NSString stringWithFormat:(@"Response: %@"), output]);

    NSDictionary *nodes = [resultsDictionary objectForKey:@"nodes"];
    NSObject *node = [nodes objectForKey:@"node"];

結果の次の部分を取得する方法がわかりません。ノード キーは見つかりましたが、次のキーはありません。ここで欠けている基本的なことは何か分かりますか?

4

1 に答える 1

3

「ノード」は配列です。これを試してください:

NSArray *nodes = resultsDictionary[@"nodes"];
NSDictionary *node = nodes[0];
node = node[@"node"]
于 2013-04-20T11:09:26.743 に答える