[英]IOS Get an Array inside NS(Mutable)Dictionary
我試圖在NSMutableDictionary中獲取一個如下所示的數組:
{
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”的所有對象創建數組的方法是什么?
您發布的是NSDictionary
的描述(從現在開始稱之為myDict
)。 從fotos
數組中獲取所有nombre
值的最快方法是:
NSArray *nombres = [myDict valueForKeyPath:@"fotos.nombre"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.