Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 从嵌套在plist文件中的NSDictionary获取字符串_Cocoa_Arrays_Nsstring_Nsdictionary - Fatal编程技术网

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

Cocoa 从嵌套在plist文件中的NSDictionary获取字符串,cocoa,arrays,nsstring,nsdictionary,Cocoa,Arrays,Nsstring,Nsdictionary,我试图从包含嵌套字典的plist文件中获取字符串。这是plist: <dict> <key>DataPoints</key> <array> <dict> <key>source</key> <string>BloomBerg</string> <key>date</k

我试图从包含嵌套字典的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>

我得到的是数组和dict的计数,而不是字符串的值。可能做了一些简单的错误…

最后一行,你把
NSLog(@“…”,source)。您不想要
NSLog(@“%@”,源代码)

Pfffff。。。花了我整个下午。。。对不起,谢谢你的帮助!
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);