【问题标题】:Getting string from NSDictionary nested in a plist file从嵌套在 plist 文件中的 NSDictionary 获取字符串
【发布时间】:2010-01-31 17:00:00
【问题描述】:

我正在尝试从包含嵌套字典的 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);

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

【问题讨论】:

    标签: cocoa arrays nsstring nsdictionary


    【解决方案1】:

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

    【讨论】:

    • Pfffff...花了我整个下午...抱歉,感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多