0

こんにちはみんな私は次のplistファイルをメモリに読み込み、結果を使っていくつかの計算を行いたいと思います。plistファイルは次のようになります。これは構造を示すための一部にすぎません。

<dict>
<key>Stations</key>
<array>
    <dict>
        <key>Name</key>
        <string>Hatfield</string>
        <key>Coords</key>
        <dict>
            <key>Lat</key>
            <integer>0</integer>
            <key>Long</key>
            <integer>0</integer>
        </dict>
        <key>Routes</key>
        <array>
            <dict>
                <key>Name</key>
                <string>H1 Hatfield - Brooklyn</string>
                <key>Stops</key>
                <array>
                    <dict>
                        <key>Name</key>
                        <string>Burnett St &amp; Festival St</string>
                        <key>Coords</key>
                        <dict>
                            <key>Lat</key>
                            <string>-25.75081</string>
                            <key>Long</key>
                            <string>28.23272</string>
                        </dict>
                    </dict>
                    <dict>
                        <key>Name</key>
                        <string>University Rd &amp; Lynwood Rd</string>
                        <key>Coords</key>
                        <dict>
                            <key>Lat</key>
                            <string>-25.75592</string>
                            <key>Long</key>
                            <string>28.22517</string>
                        </dict>
                    </dict>
                    <dict>
                        <key>Name</key>
                        <string>Roper St &amp; Charles St</string>
                        <key>Coords</key>
                        <dict>
                            <key>Lat</key>
                            <string>-25.76463</string>
                            <key>Long</key>
                            <string>28.22737</string>
                        </dict>
                    </dict>

現在、私は以下を使用してそれらを読み込もうとしています。

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Busses.plist"];

NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

NSMutableArray *arrayOfStationsFromFile = [[[NSMutableArray alloc] initWithObjects:[plistData objectForKey:@"Stations"], nil] retain];


for(int i = 0; i < [arrayOfStationsFromFile count]; i++)
{

    NSDictionary *stationWithBusses = (NSDictionary *)[[arrayOfStationsFromFile objectAtIndex:i] retain];
    NSMutableArray *routes = [[stationWithBusses objectForKey:@"Routes"] retain];
    for(int j = 0; j < [routes count]; j++)
    {
        NSMutableDictionary *routesData = [routes objectAtIndex:j];
        NSString *name = [routesData objectForKey:@"Name"];
        NSMutableArray *stops = [routesData objectForKey:@"Stops"];
        for(int x = 0; x < [stops count]; x++)
        {
            NSMutableDictionary *stopsData = [stops objectAtIndex:x];
            NSString *subName = [stopsData objectForKey:@"Name"];
            NSMutableDictionary *coords = [stopsData objectForKey:@"Coords"];
            NSString *latt = [coords objectForKey:@"Lat"];
            NSString *longs = [coords objectForKey:@"Long"];
            CLLocationCoordinate2D coordinate;
            coordinate.latitude = [latt longLongValue];
            coordinate.longitude = [longs longLongValue];
            [busses addObject:[[Busses alloc] initWithName:name subName:subName coordinate:coordinate]];
        }
    }
}

しかし、私はこの行でSIGABRTを取得します

NSMutableArray *routes = [[stationWithBusses objectForKey:@"Routes"] retain];

コンソール出力の最初の行:

2011-08-30 12:31:57.699 GautrainiPhone[12633:e903] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x5ba6c10

私が間違っていることについて何か考えはありますか?

4

2 に答える 2

0

メッセージ+場所が意味するstationWithBussesのはNSArray(ではないNSDictionary

于 2011-08-30T10:45:54.150 に答える
0

最初の行を私のコードに置き換えてみてください:

NSString *errorDesc = nil;
NSPropertyListFormat format;
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:finalPath];
NSMutableDictionary *plistData = (NSMutableDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
NSMutableArray *arrayOfStationsFromFile = [NSMutableArray arrayWithArray:[plistData valueForKey:@"Stations"]];
于 2011-08-30T11:04:05.830 に答える