gpt4 book ai didi

ios - 在 foreach 中从 NSDictionary 获取值?

转载 作者:行者123 更新时间:2023-12-01 17:18:34 27 4
gpt4 key购买 nike

我有一个 View ,上面有 tableviewcells,加载了不同的“键值”作为标签。当我点击一个时,我会打开另一个 View 。但是在这里,我只为那个键传递字典,例如我会传递这个:

{
key = Budget;
value = {
"2012 Budget Report" = {
active = 0;
author = "xxxxx xxxxxx";
date = "October 27, 2012";
description = "Example";
dl = "53 downloads";
email = "xxx@xxxxx.com";
ext = DOCX;
fortest = "Tuesday, November 6";
id = 5;
subject = budget;
testdate = "Tuesday, November 6";
title = "Budget spreadSheet";
};
"2005 - 2008 Budget Report" = {
active = 0;
author = "xxxxxxx xxxxx";
date = "November 3, 2012";
description = "Example";
dl = "18 downloads";
email = "xxxxx@xxxxx.com";
ext = DOCX;
title = "Budget report";
};
};
}

我如何获得这些值中的每一个?谢谢。

请注意:值数组中的标题可能会更改...可以添加更多,可以删除一个,所以我需要一个通用的解决方案。

最佳答案

考虑到您传递的字典保存在 iDictionary .

NSDictionary *iDictionary // Input Dictionary;
NSDictionary *theValues = [NSDictionary dictionaryWithDictionary:[iDictionary valueForKey:@"value"]];

for (NSString *aKey in [theValues allKeys]) {
NSDictionary *aValue = [theValues valueForKey:aKey];
NSLog(@"Key : %@", aKey);
NSLog(@"Value : %@", aValue);

// Extract individual values
NSLog(@"Author : %@", [aValue objectForKey:@"author"]);

// If the titles are dynamic
for (NSString *aSubKey in [aValue allKeys]) {
NSString *aSubValue = [aValue objectForKey:aSubKey];

NSLog(@"SubKey : %@, SubValue = %@", aSubKey, aSubValue);
}
}

关于ios - 在 foreach 中从 NSDictionary 获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13373821/

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