IOS Get array in NS dictionary (Mutable)

I am trying to get an array inside an NSMutableDictionary that looks like this:

{
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 =     (
);
}

And I use this code:

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

But the "fotoarray" array remains empty, trying to get information from NSMutableArray.

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

How to create an array with all objects named "nombre"?

+5
source share
1 answer

What you posted is a description NSDictionary(lets you call it myDictfrom now on). The fastest way to get all values nombrefrom an array fotos:

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

All Articles