1

我在 NSDictionary 中有这个回复

Venue {
    canonicalUrl = "https://foursquare.com/v/aeroporto-de-congonhas-cgh/4b2d0e1af964a52037cd24e3";
    categories = ({
            icon = {
                prefix = "https://foursquare.com/img/categories_v2/travel/airport_";
                suffix = ".png";
            };
            id = 4bf58dd8d48988d1ed931735;
            name = Aeroporto;
            pluralName = Aeroportos;
            primary = 1;
            shortName = Aeroporto;
        });
    contact = {
        formattedPhone = "+55 11 5090-9000";
        phone = "+551150909000";
        twitter = infraerobrasil;
    };
    hereNow = {
        count = 115;
        groups = ({
                count = 115;
                items = ();
                name = "Outras pessoas aqui";
                type = others;
            });
    };
    id = 4b2d0e1af964a52037cd24e3;
    likes = {
        count = 0;
        groups = ();
    };
    location = {
        address = "Av. Washington Luiz, S/N";
        cc = BR;
        city = "S\U00e3o Paulo";
        country = Brazil;
        crossStreet = "Av. dos Bandeirantes";
        distance = 2355;
        lat = "-23.62596730840704";
        lng = "-46.65872097015381";
        postalCode = "04626-911";
        state = SP;
    };
    name = "Aeroporto de Congonhas (CGH)";
    referralId = "v-1370609443";
    restricted = 1;
    specials = {
        count = 0;
        items = ();
    };
    stats = {
        checkinsCount = 556928;
        tipCount = 1721;
        usersCount = 126970;
    };
    url = "http://www.infraero.gov.br";
    verified = 0;
}

我正在尝试从类别中获取复数名称....

我的代码是:

      -(NSArray*)convertToObjects:(NSArray*)venues{
    NSMutableArray *objects = [NSMutableArray arrayWithCapacity:venues];
    for (NSDictionary *v  in venues) {
        NSLog(@"Venue %@", v);
        NSLog(@"Categoria %@", v[@"categories"][@"pluralName"]); //only here I'm getting error...without this line, name, venue id, address and distance are right
        FSVenue *ann = [[FSVenue alloc]init];
        ann.name = v[@"name"];
        ann.venueId = v[@"id"];
        ann.location.address = v[@"location"][@"address"];
        ann.location.distance = v[@"location"][@"distance"];
        [ann.location setCoordinate:CLLocationCoordinate2DMake([v[@"location"][@"lat"] doubleValue],
                                                      [v[@"location"][@"lng"] doubleValue])];
        [objects addObject:ann];
    }
    return objects;
}

但我收到此错误:

-[__NSCFArray objectForKeyedSubscript:]:无法识别的选择器发送到实例 0x1f3e3100 2013-06-07 09:54:51.641 Moodpin[13660:907] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1f3e3100' * First throw call stack: (0x331172a3 0x3ae3f97f 0x3311ae07 0x33119531 0x33070f68 0xb3cfb 0xe9d9f 0xb8eab 0xba681 0x33a526fd 0x339921f9 0x33992115 0x32df445f 0x32df3b43 0x32e1bfcb 0x3305d74d 0x32e1c42b 0x32d8003d 0x330ec683 0x330ebee9 0x330eacb7 0x3305debd 0x3305dd49 0x36c362eb 0x34f73301 0xd9147 0x3b276b20) libc++abi.dylib: terminate称为抛出异常

4

1 回答 1

3

它看起来像是categories一个包含一个元素的数组。[@"pluralName"]您不能在 an 上使用带有字符串的下标NSArray- 它仅适用于字典。

试试这个——获取categories, 并选择它的初始元素。然后应用于[@"pluralName"]该元素,如下所示:

NSLog(@"Categoria %@", v[@"categories"][0][@"pluralName"]);
//                                     ^^^
于 2013-06-07T12:57:22.327 回答