Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting string from NSDictionary nested in a plist file
    primarykey
    data
    text
    <p>I am trying to get a string out of a plist file that contains a nested dictionary. This is the plist:</p> <pre><code>&lt;dict&gt; &lt;key&gt;DataPoints&lt;/key&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;source&lt;/key&gt; &lt;string&gt;BloomBerg&lt;/string&gt; &lt;key&gt;date&lt;/key&gt; &lt;date&gt;2010-01-31T14:54:13Z&lt;/date&gt; &lt;key&gt;value&lt;/key&gt; &lt;integer&gt;1233&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;source&lt;/key&gt; &lt;string&gt;BloomBerg&lt;/string&gt; &lt;key&gt;date&lt;/key&gt; &lt;date&gt;2010-02-02T14:54:13Z&lt;/date&gt; &lt;key&gt;value&lt;/key&gt; &lt;integer&gt;1235&lt;/integer&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;source&lt;/key&gt; &lt;string&gt;BloomBerg&lt;/string&gt; &lt;key&gt;date&lt;/key&gt; &lt;date&gt;2010-01-31T14:54:13Z&lt;/date&gt; &lt;key&gt;value&lt;/key&gt; &lt;integer&gt;1230&lt;/integer&gt; &lt;/dict&gt; &lt;/array&gt; &lt;/dict&gt; </code></pre> <p>Here is my code:</p> <pre><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); </code></pre> <p>I get the counts of the arrays and the dicts but not the value of the string. Probably doing something simple wrong...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload