gpt4 book ai didi

ios - 如何在以下 NSDictionary 中下钻?

转载 作者:行者123 更新时间:2023-12-01 19:17:42 25 4
gpt4 key购买 nike

我为我的 UiTableView 的每个单元格获取以下 NSDictionary。我必须能够向下钻取并获得下面 Assets 子结构中的第一个 id 值。

{
assets = (
{
"chunk_size" = 262144;
file = {
"is_dirty" = 0;
"mongo_grid_f_s_file" = {
file = {
"_id" = {
"$id" = 503a58e09b41648f69000001;
};
chunkSize = 262144;
filename = "/private/var/tmp/phpPPZsUf";
length = 5849;
md5 = 5f2700f4d953ef866fe1d4967f9965fb;
name = Image1;
uploadDate = {
sec = 1346001120;
usec = 819000;
};
};
gridfs = {
chunks = {
w = 1;
wtimeout = 10000;
};
"chunks_name" = "assets.chunks";
"files_name" = "assets.files";
w = 1;
wtimeout = 10000;
};
};
};
id = 503a58e09b41648f69000001;
length = 5849;
md5 = 5f2700f4d953ef866fe1d4967f9965fb;
name = Image1;
"upload_date" = "0.81900000 1346001120";
},
{
"chunk_size" = 262144;
file = {
"is_dirty" = 0;
"mongo_grid_f_s_file" = {
file = {
"_id" = {
"$id" = 503a58e09b41648f69000004;
};
chunkSize = 262144;
filename = "/private/var/tmp/phphxvI3H";
length = 1551;
md5 = f193ffe87eb0138608a206dcf72bf704;
name = Image2;
uploadDate = {
sec = 1346001120;
usec = 841000;
};
};
gridfs = {
chunks = {
w = 1;
wtimeout = 10000;
};
"chunks_name" = "assets.chunks";
"files_name" = "assets.files";
w = 1;
wtimeout = 10000;
};
};
};
id = 503a58e09b41648f69000004;
length = 1551;
md5 = f193ffe87eb0138608a206dcf72bf704;
name = Image2;
"upload_date" = "0.84100000 1346001120";
}
);
coordinates = {
latitude = "37.78584";
longitude = "-122.4064";
};
"created_at" = "2012-08-26T12:12:00-0500";
id = 503a58e09b4164cf5a00000a;
"number_of_cars" = 1;

}

我尝试了以下方法:
 NSDictionary * classifiedAssets = [classified objectForKey:@"assets"];

然后为了获取每个 id,我已经完成了:
[classifiedImages objectForKey:@"id"]

然而,我得到的是:
(503a58e09b41648f69000001, 503a58e09b41648f69000004)

我希望取回各种 ID 的 NSArray,而不是括号逗号分隔的列表。

有小费吗?

最佳答案

我想你可能已经拥有了你需要的东西;这是解释:

NSDictionary * classifiedAssets = [classified objectForKey:@"assets"];

不完全是您所期望的:您可能认为它是一个 NSDictionary(由于您键入了变量),但它实际上是一个 NSArray(由于 JSON 中的括号而不是花括号)。然后这个:
[classifiedImages objectForKey:@"id"]
// by which I *assume* you mean:
[classifiedAssets valueForKey:@"id"]

实际上是在利用 NSArrays 的一个漂亮特性:调用 valueForKey: on an NSArray 为您提供调用 valueForKey: 的结果的 NSArray在每个成员身上。

我假设您正在谈论 NSLog 行中的括号和逗号。在这种情况下,用括号括起来的逗号分隔的一组事物表示一个 NSArray(尝试记录它的 class 并查看)

关于ios - 如何在以下 NSDictionary 中下钻?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12132629/

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