繁体   English   中英

IOS在NS(Mutable)Dictionary中获取一个数组

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM