2012-08-31 17 views
5

我試圖得到的NSMutableDictionary裏的數組,看起來像這樣:IOS獲取內部NS數組(可變)字典

{ 
coments =  (
); 
"foto_user" = "<null>"; 
fotos =  (
      { 
     fecha = "2012-08-31 19:44:31"; 
     id = 4926; 
     nombre = "image5773.jpg"; 
     posicion = 0; 
     ruta = "img/"; 
     tipo = 1; 
    }, 
      { 
     fecha = "2012-08-31 19:44:31"; 
     id = 4927; 
     nombre = "image1779.jpg"; 
     posicion = 0; 
     ruta = "img/"; 
     tipo = 1; 
    }, 
      { 
     fecha = "2012-08-31 19:44:31"; 
     id = 4928; 
     nombre = "image5938.jpg"; 
     posicion = 0; 
     ruta = "img/"; 
     tipo = 1; 
    }, 
      { 
     fecha = "2012-08-31 19:44:32"; 
     id = 4929; 
     nombre = "image4424.jpg"; 
     posicion = 0; 
     ruta = "img/"; 
     tipo = 1; 
    } 
); 
"have_coments" = 0; 
id = 40505; 
"id_lugar" = "<null>"; 
"id_pais" = 28; 
"id_user" = "<null>"; 
iso = fr; 
link = "<null>"; 
lugar = Paris; 
"nombre_pais" = "France"; 
root = "http://www.domain.com/"; 
tags =  (
); 
titulo = "Sunset"; 
"url_share" = "http://www.friktrip.com/experiencia/40505"; 
videos =  (
); 
} 

,我使用此代碼:

   //Get data from dictionary 
      NSMutableArray *foto = [[NSMutableArray alloc]init]; 
      foto = [OnlineObjects objectAtIndex:1]; 

但「fotoarray」數組保持空嘗試從NSMutableArray獲取信息。

   //Get only the nombre Key of the NSMutableArray 
      NSArray *fotoarray = [foto valueForKey:@"nombre"]; 

什麼是使用鍵名爲「nombre」的所有對象創建一個數組的方法?

+1

1)你已經張貼是不是一個可變數組,是一個'NSDictionary'。 2)什麼是'OnlineObjects'? – Alladinian

回答

13

您發佈的內容是對NSDictionary的描述(從現在開始稱它爲myDict)。從fotos陣列獲取所有​​值最快的方法是這樣的:

NSArray *nombres = [myDict valueForKeyPath:@"fotos.nombre"]; 
+0

謝謝!它像一個迷人的工作! – Ben

+0

不客氣。隨意接受它是正確的。 – Alladinian

+0

偉大的實例。 :) –