gpt4 book ai didi

iphone - 获取随机 NSDictionary 键?

转载 作者:行者123 更新时间:2023-12-03 16:43:34 25 4
gpt4 key购买 nike

StackOverflow 社区您好,

<plist>
<dict>
<key>Non Random Key</key>
<dict>
<key>Random Key</key>
<dict>
<key>Hello</key>
<string>Hey</string>
<key>Banana</key>
<string>Bread</string>
</dict>
</dict>
</dict>
</plist>

这是我的 Plist 文件.../this/is/the/path.plist

现在我想从“Hello”中获取“Hey”字符串。

非随 secret 钥的解决方案!但我有一个随 secret 钥,这也不是解决方案......

NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/this/is/the/path.plist"];

NSString *value;
value = [plistDict objectForKey:@"/Non Random Key/Random Key/Hello"];
// value is "Hey"

但是它如何与“随 secret 钥”一起使用?

提前谢谢您。

也许,你可以解释一下,我如何设置随 secret 钥?还有顶部的示例,但我会“设置”而不是“获取”:)

最佳答案

您可以迭代“非随机键”字典。这应该有帮助:NSDictionary iterate

NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/this/is/the/path.plist"];

NSDictionary *nonRandomDic = [plistDic valueForKey:@"NonRandomKey"];


NSEnumerator *enumerator = [nonRandomDic keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
  NSString *tmp = [nonRandomDic objectForKey:key];
NSLog(@"Your String %@ from the Random Key %@", tmp, key);
}

关于iphone - 获取随机 NSDictionary 键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9525518/

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