gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 04:16:30 28 4
gpt4 key购买 nike

我正在尝试在 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"];

关于IOS 在 NS(Mutable)Dictionary 中获取一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12221008/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com