0

私のjsonの攪拌は次のとおりです。

{

"locations" :[
       {                
        id = 0;
        lat = "41.653048";
        long = "-0.880677";
        name = "LIMPIA";
       },
       {
        id = 1;
        lat = "41.653048";
        long = "-0.890677";
        name = "LIMPIA2";
       }
  ]

}

使用:

NSDictionary * root = [datos_string1 JSONValue];
NSArray *bares = (NSArray *) [root objectForKey:@"locations"];  

   for (NSArray * row in bares) {
    NSString *barName1 = [bares valueForKey:@"name"];
    NSLog(@"%@",barName1);
    }

NSlog から取得し、2 回 otput ( LIMPIA、LIMPIA2 )

だから何かが間違っている。(マップキット アプリで使用するために) 各アイテムの単一値パラメーター (lat、lon、nombre) を抽出する必要があります。私たちを手伝ってくれますか?

4

1 に答える 1

1

I need to estract di single value parameter (lat, lon and nombre) for each item (in order to use in a mapkit app)

If I understand your question correctly, you're trying to access each value in each dictionary in the locations array, is that right?

In order to access each value (if that is indeed your question), this should work:

NSDictionary *root = [datos_string1 JSONValue];
NSArray *bares = (NSArray *)[root objectForKey:@"locations"];  

// Each item in the array is a dictionary, not an NSArray
for (NSDictionary *dict in bares) {
    // Loop over keys
    for (NSString *key in [dict allKeys]) {
        NSLog(@"dict[%@] == %@", key, [dict objectForKey:key]);
    }
}
于 2012-05-12T23:59:01.087 に答える