gpt4 book ai didi

ios - 如何从字典中读出数据?

转载 作者:行者123 更新时间:2023-11-29 13:37:56 25 4
gpt4 key购买 nike

我有一个看起来像这样的 plist:

<dict>
<key>Aaron</key>
<dict>
<key>number</key>
<string>1234</string>
<key>country</key>
<string>Spanien</string>
<key>year</key>
<string>1989</string>
</dict>
<key>Abagail</key>
<dict>
<key>number</key>
<string>1234</string>
<key>country</key>
<string>Frankrike</string>
<key>year</key>
<string>2001</string>
</dict>
<key>Abbey</key>
<dict>
<key>number</key>
<string>1289</string>
<key>country</key>
<string>Tyskland</string>
<key>year</key>
<string>2009</string>
</dict>

通过这段代码,我得到了每个对象的键:

NSLog(@"test %@", [dict objectForKey:key2]);

如何获取每个对象的字符串值。我的 viewdidload 看起来像这样

NSString *path = [[NSBundle mainBundle] pathForResource:@"vin"
ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path];

self.allNames = dict;

NSString *key2 = viewTitle;

NSLog(@"test %@", [dict objectForKey:key2]);

最佳答案

基于上面的 plist,您可以访问 country 的值:

NSDictionary* record2 = (NSDictionary*)[dict objectForKey:key2];
NSString* country = (NSString*)[record2 objectForKey:@"country"];

关于ios - 如何从字典中读出数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9994456/

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