2010-01-31 72 views
1

我想從包含嵌套字典的plist文件中獲取一個字符串。這是plist中:從嵌套在plist文件中的NSDictionary中獲取字符串

<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); 

我得到陣列的計數和類型的字典而不是字符串的值。大概做一些簡單的錯事...

回答

3

最後一行,你把NSLog(@"…", source);。你不想要NSLog(@"%@", source);

+0

Pfffff ...帶了我整個下午...抱歉,感謝您的幫助! – Nick 2010-01-31 17:21:07

相關問題