gpt4 book ai didi

cocoa - 从嵌套在 plist 文件中的 NSDictionary 获取字符串

转载 作者:行者123 更新时间:2023-12-03 17:00:23 25 4
gpt4 key购买 nike

我正在尝试从包含嵌套字典的 plist 文件中获取字符串。这是plist:

<dict>
<key>DataPoints</key>
<array>
<dict>
<key>source</key>
<string>BloomBerg</string>
<key>date</key>
<date>2010-01-31T14:54:13Z</date>
<key>value</key>
<integer>1233</integer>
</dict>
<dict>
<key>source</key>
<string>BloomBerg</string>
<key>date</key>
<date>2010-02-02T14:54:13Z</date>
<key>value</key>
<integer>1235</integer>
</dict>
<dict>
<key>source</key>
<string>BloomBerg</string>
<key>date</key>
<date>2010-01-31T14:54:13Z</date>
<key>value</key>
<integer>1230</integer>
</dict>
</array>
</dict>

这是我的代码:

NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"sampledata.plist"];
NSDictionary* plotDictionary = [[NSDictionary dictionaryWithContentsOfFile:path] retain];
NSArray* plotData = [plotDictionary objectForKey:@"DataPoints"];

NSLog(@"Got the dict %d",[plotData count]);

NSDictionary* plotPoint = [plotData objectAtIndex:1];

NSLog(@"Got the point %d",[plotPoint count]);

NSString* source = [plotPoint objectForKey:@"source"];
NSLog(@"...", source);

我得到了数组和字典的计数,但没有得到字符串的值。可能做了一些简单的错误......

最佳答案

最后一行,你输入NSLog(@"…", source);。你不想要 NSLog(@"%@", source); 吗?

关于cocoa - 从嵌套在 plist 文件中的 NSDictionary 获取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2172514/

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