0

我有以下网络服务。

"club": {

    "staff": [ … ],
    "trainingen": [ … ],
    "team": [
        {
            "name": "Baerts Lennert",
            "number": "0",
            "position": "Doelman",
            "birthdate": "1996-09-01",
            "red_cards": 0,
            "yellow_cards": 0,
            "news": [
                {
                    "nid": "1158",
                    "player_id": 1
                },
                {
                    "nid": "1148",
                    "player_id": 1
                },

            ]
        },

我用以下方法得到这个。

+ (NSArray *)getPlayNewsWithIndex:(int)index
{
    NSLog(@"index is hier %d",index);
    NSString *request = [NSString stringWithFormat:@"http://www.krcgenk.be/mobile/json/request/club/type/ipad"];
    NSLog(@"log1");
    NSArray *arr = [[self executeGenkFetch:request] valueForKeyPath:@"club.team"];
    NSLog(@"log2");
    NSArray *arr2 = [[arr objectAtIndex:index] valueForKey:@"news"];
    NSLog(@"log3");
    return arr2;
}

在它记录“log1”之后。功能继续需要一段时间。我现在的问题是,这怎么可能?

编辑

这是我的 executeGenkFetch

+ (NSDictionary *)executeGenkFetch:(NSString *)query
{
    query = [NSString stringWithFormat:@"%@", query];
    query = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    // NSLog(@"[%@ %@] sent %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), query);
    NSData *jsonData = [[NSString stringWithContentsOfURL:[NSURL URLWithString:query] encoding:NSUTF8StringEncoding error:nil] dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:&error] : nil;
    if (error) NSLog(@"[%@ %@] JSON error: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), error.localizedDescription);
    // NSLog(@"[%@ %@] received %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), results);
    return results;
}
4

0 回答 0