2010-01-31 4 views
1

Je tente d'extraire une chaîne d'un fichier plist contenant un dictionnaire imbriqué. Ceci est le plist:Obtention d'une chaîne à partir de NSDictionary imbriquée dans un fichier 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> 

Voici mon code:

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

Je reçois les chefs des tableaux et les dicts mais pas la valeur de la chaîne. Probablement faire quelque chose de mal ...

Répondre

3

Dernière ligne, vous mettez NSLog(@"…", source);. Tu ne veux pas NSLog(@"%@", source);?

+0

Pfffff ... M'a pris tout l'après-midi ... Désolé et merci pour l'aide! – Nick

Questions connexes