0

返された一連のツイートをループして、テキスト コンポーネントと座標を取得しています。以下のようにコードを設定しました。これはテキストを取得しますが、座標は取得しません。何が間違っているのかわかりません。返されたパスを確認しましたが、返された文字列の一部に次が含まれています

"geo":{"coordinates":[51.479361,-0.215066],"type":"Point"},

したがって、間違いなく座標が返されます。これが私のコードです...

for (NSDictionary *tweet in results) {
                 // Get the tweet
                 NSString *twittext = [tweet objectForKey:@"text"];

                 // Save the tweet to the twitterText array
                 [_twitterText addObject:twittext];


id jsonResult = [tweet valueForKeyPath:@"geo.coordinates"];
                 if ([NSNull null] != jsonResult) {
                     if (2 == [jsonResult count]) {
                         NSDecimalNumber* longitude = [jsonResult objectAtIndex:0];
                         NSDecimalNumber* latitude = [jsonResult objectAtIndex:1];
                         if (longitude && latitude) {

                             // here you have your coordinates do whatever you like
                             [twitterLocation addObject:[NSString stringWithFormat:@"%@,%@", latitude, longitude]];
                         }
                         else {
                             NSLog(@"Warning: bad coordinates: %@", jsonResult);
                         }
                     }
                     else {
                         NSLog(@"Warning: bad coordinates: %@", jsonResult);
                     }
                 }*/
             }
4

1 に答える 1

2

まずcheck、取得した値がNSStringまたはNSDecimalNumber

if([jsonResult objectAtIndex:0] && [jsonResult objectAtIndex:1])  
{
   if([[jsonResult objectAtIndex:0] isKindOfClass:[NSString class]])
    {  
       double longitude = [[jsonResult objectAtIndex:0] doubleValue];
       double latitude = [[jsonResult objectAtIndex:1] doubleValue];
    }
}
于 2013-01-18T11:31:35.247 に答える